Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save NikosAlexandris/7a527ef48eeecc5d4cd2243091ea7c40 to your computer and use it in GitHub Desktop.
Save NikosAlexandris/7a527ef48eeecc5d4cd2243091ea7c40 to your computer and use it in GitHub Desktop.
Issue with numpy's `numpy.genfromtxt` and 'usecols' argument
# hardcodings
working_directory = '/home/jovyan/binder/'
csvdata = 'who_covid_19_sit_rep_time_series.csv'
# librairies
import os
import numpy
# get data from csv file
filename = os.path.join (working_directory, csvdata)
locations = numpy.genfromtxt(filename,
                             dtype=numpy.unicode_,
                             delimiter=',',
                             skip_header=7,
                             usecols=range(0,1),
                             encoding="utf-8-sig"
            )
locations
array(['Guangdong', 'Henan', 'Zhejiang', 'Hunan', 'Anhui', 'Jiangxi',
       'Shandong', 'Jiangsu', 'Chongqing', 'Sichuan', 'Heilongjiang',
       'Beijing', 'Shanghai', 'Hebei', 'Fujian', 'Guangxi', 'Shaanxi',
       'Yunnan', 'Hainan', 'Guizhou', 'Tianjin', 'Shanxi', 'Liaoning',
       'Hong Kong', 'Jilin', 'Gansu', 'Xinjiang', 'Inner Mongolia',
       'Ningxia', 'Taiwan', 'Qinghai', 'Macau', 'Xizang', 'Unspecified*',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
       '', '', '', '', '', '', '', '', '', '', '',
       'Case on an international conveyance', 'Confirmed', 'Deaths',
       'Confirmed', 'Deaths', 'Confirmed', 'Deaths', 'Confirmed',
       'Deaths', 'Confirmed', 'Deaths', 'Confirmed', 'Deaths'],
      dtype='<U35')
locations = numpy.genfromtxt(filename,
                             dtype=numpy.unicode_,
                             delimiter=',',
                             skip_header=7,
                             usecols=range(1,2),
                             encoding="utf-8-sig"
            )
locations
array(['China', 'China', 'China', 'China', 'China', 'China', 'China',
       'China', 'China', 'China', 'China', 'China', 'China', 'China',
       'China', 'China', 'China', 'China', 'China', 'China', 'China',
       'China', 'China', 'China', 'China', 'China', 'China', 'China',
       'China', 'China', 'China', 'China', 'China', 'China', 'China',
       'Singapore', 'Philippines', 'Japan', 'Republic of Korea',
       'Malaysia', 'Australia', 'New Zealand', 'Vietnam', 'Mongolia',
       'Brunei Darussalam', 'Cambodia',
       "Lao People's Democratic Republic", 'Fiji', 'Papua New Guinea',
       'Guam', 'French Polynesia', 'Northern Mariana Islands',
       'New Caledonia', 'Russian Federation', 'The United Kingdom',
       'Spain', 'Italy', 'Germany', 'Turkey', 'France', 'Belgium',
       'Netherlands', 'Belarus', 'Sweden', 'Portugal', 'Switzerland',
       'Ireland', 'Ukraine', 'Poland', 'Romania', 'Israel', 'Austria',
       'Denmark', 'Kazakhstan', 'Serbia', 'Armenia', 'Czechia', 'Norway',
       'Republic of Moldova', 'Finland', 'Azerbaijan', 'Luxembourg',
       'Tajikistan', 'Hungary', 'Uzbekistan', 'Greece',
       'Bosnia and Herzegovina', 'Bulgaria', 'North Macedonia', 'Croatia',
       'Estonia', 'Kyrgyzstan', 'Iceland', 'Lithuania', 'Slovakia',
       'Slovenia', 'Albania', 'Latvia', 'Cyprus', 'Georgia', 'Andorra',
       'San Marino', 'Malta', 'Montenegro', 'Monaco', 'Liechtenstein',
       'Holy See', 'Kosovo', 'Isle of Man', 'Jersey', 'Guernsey',
       'Faroe Islands', 'Gibraltar', 'Greenland', 'India', 'Bangladesh',
       'Indonesia', 'Thailand', 'Maldives', 'Nepal', 'Sri Lanka',
       'Myanmar', 'Bhutan', 'Timor-Leste', 'Iran', 'Saudi Arabia',
       'Pakistan', 'Qatar', 'United Arab Emirates', 'Kuwait', 'Egypt',
       'Afghanistan', 'Oman', 'Bahrain', 'Morocco', 'Iraq', 'Sudan',
       'Djibouti', 'Somalia', 'Lebanon', 'Tunisia', 'Jordan', 'Yemen',
       'Libya', 'Syrian Arab Republic', 'occupied Palestinian territory',
       'United States of America', 'Brazil', 'Peru', 'Chile', 'Canada',
       'Mexico', 'Ecuador', 'Colombia', 'Dominican Republic', 'Argentina',
       'Panama', 'Bolivia', 'Honduras', 'Guatemala', 'El Salvador',
       'Haiti', 'Cuba', 'Venezuela', 'Costa Rica', 'Paraguay',
       'Nicaragua', 'Uruguay', 'Jamaica', 'Guyana', 'Trinidad and Tobago',
       'Bahamas', 'Barbados', 'Suriname',
       'Saint Vincent and the Grenadines', 'Antigua and Barbuda',
       'Grenada', 'Saint Lucia', 'Belize', 'Dominica',
       'Saint Kitts and Nevis', 'Puerto Rico', 'French Guiana',
       'Martinique', 'Guadeloupe', 'Cayman Islands', 'Bermuda', 'Aruba',
       'Sint Maarten', 'United States Virgin Islands', 'Saint Martin',
       'Curaçao', 'Falkland Islands (Malvinas)',
       'Turks and Caicos Islands', 'Montserrat', 'British Virgin Islands',
       'Saint Barthélemy', '"Bonaire', 'Anguilla',
       'Saint Pierre and Miquelon', 'South Africa', 'Nigeria', 'Algeria',
       'Ghana', 'Cameroon', 'Guinea', 'Senegal',
       'Democratic Republic of the Congo', 'Côte d’Ivoire', 'Gabon',
       'Kenya', 'Guinea-Bissau', 'Mali', 'Ethiopia', 'Zambia',
       'Central African Republic', 'Equatorial Guinea', 'South Sudan',
       'Niger', 'Burkina Faso', 'Sierra Leone', 'Madagascar', 'Chad',
       'Congo', 'Mauritania', 'United Republic of Tanzania', 'Cabo Verde',
       'Uganda', 'Togo', 'Rwanda', 'Malawi', 'Mauritius', 'Liberia',
       'São Tomé and Príncipe', 'Eswatini', 'Mozambique', 'Benin',
       'Zimbabwe', 'Angola', 'Burundi', 'Comoros', 'Eritrea', 'Botswana',
       'Gambia', 'Namibia', 'Seychelles', 'Lesotho', 'Mayotte', 'Réunion',
       'Other', '', '', '', '', '', '', '', '', '', '', '', ''],
      dtype='<U32')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment