rodrigosantosbr

[Py] XLS / Excel files - How to read using Pandas

Mar 21st, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. import pandas
  2. pathfile = '/home/user/federative_unit.xlsx'
  3. df = pandas.read_excel(pathfile,converters={
  4.     'id':int,
  5.     'objectid':str,
  6.     'abbreviation':str,
  7.     'iso3166_2':str,
  8.     'name':str,
  9.     'name_unaccent':str,
  10.     'estimated_population':int,
  11.     'adjective':str,
  12.     'adjective_alternative':str,
  13.     'macroregion':str,
  14.     'wikipedia_pt':str,
  15.     'website':str
  16. })
  17. df = df.fillna('')
  18. for i in df.index:
  19.     _id = df['objectid'][i].replace(' ','')
  20.     abbreviation = (df['abbreviation'][i]).replace('"','')
  21.     ibge_id = df['ibge_id'][i]
  22.     iso3166_2 = df['iso3166_2'][i]
  23.     osm_relation_id = df['osm_relation_id'][i]
  24.     wikidata_id = df['wikidata_id'][i]
  25.     name = df['name'][i]
  26.     name_unaccent = df['name_unaccent'][i]
  27.     estimated_population = df['estimated_population'][i]
  28.     adjective = df['adjective'][i]
  29.     adjective_alternative = df['adjective_alternative'][i]
  30.     macroregion = df['macroregion'][i]
  31.     wikipedia_pt = df['wikipedia_pt'][i]
  32.     website = df['website'][i]
  33.     timezone = df['timezone'][i]
  34.     flag_image = df['flag_image'][i]
  35.     country_abbreviation = df['country_abbreviation'][i]
Advertisement
Add Comment
Please, Sign In to add comment