Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. # Create empty DataFrame with three columns, will include index
  2. rates_df = pd.DataFrame( columns=['country_code', 'year', 'rate'])
  3. rates_df.head()
  4.  
  5. #Itterate over each row
  6. for index, row in new_world_labor_rates_df.iterrows():
  7. # print each row
  8. #print(index, row[1])
  9.  
  10. # declare variables and assign empty lists
  11. country = row[0]
  12. rate2010 = row[1]
  13. rate2011 = row[2]
  14. rate2012 = row[3]
  15. rate2013 = row[4]
  16. rate2014 = row[5]
  17. print(country)
  18.  
  19. # append the data as a dictionary to the DataFrame
  20. # data is stored in the variables by using the for loop to itterate through the rows and then appending
  21. # the correct column to the right variable
  22.  
  23. # these variables are then matched back to the DataFrame, by creating key value pairs (dictionaries)
  24. rates_df= rates_df.append({'country_code':country, 'year':'2010', 'rate':rate2010 }, ignore_index=True)
  25. rates_df= rates_df.append({'country_code':country, 'year':'2011', 'rate':rate2011 }, ignore_index=True)
  26. rates_df= rates_df.append({'country_code':country, 'year':'2012', 'rate':rate2012 }, ignore_index=True)
  27. rates_df= rates_df.append({'country_code':country, 'year':'2013', 'rate':rate2013 }, ignore_index=True)
  28. rates_df= rates_df.append({'country_code':country, 'year':'2014', 'rate':rate2014 }, ignore_index=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement