Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Create empty DataFrame with three columns, will include index
- rates_df = pd.DataFrame( columns=['country_code', 'year', 'rate'])
- rates_df.head()
- #Itterate over each row
- for index, row in new_world_labor_rates_df.iterrows():
- # print each row
- #print(index, row[1])
- # declare variables and assign empty lists
- country = row[0]
- rate2010 = row[1]
- rate2011 = row[2]
- rate2012 = row[3]
- rate2013 = row[4]
- rate2014 = row[5]
- print(country)
- # append the data as a dictionary to the DataFrame
- # data is stored in the variables by using the for loop to itterate through the rows and then appending
- # the correct column to the right variable
- # these variables are then matched back to the DataFrame, by creating key value pairs (dictionaries)
- rates_df= rates_df.append({'country_code':country, 'year':'2010', 'rate':rate2010 }, ignore_index=True)
- rates_df= rates_df.append({'country_code':country, 'year':'2011', 'rate':rate2011 }, ignore_index=True)
- rates_df= rates_df.append({'country_code':country, 'year':'2012', 'rate':rate2012 }, ignore_index=True)
- rates_df= rates_df.append({'country_code':country, 'year':'2013', 'rate':rate2013 }, ignore_index=True)
- 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