Screen Link: https://app.dataquest.io/m/292/exploring-data-with-pandas%3A-intermediate/11/using-loops-with-pandas
My Code:
top_employer_by_country = {}
countries = f500['country'].unique()
for c in countries:
select_rows = f500[f500['country'] == c]
sorted_rows = select_rows.sort_values('employees', ascending = False)
onee = sorted_rows.iloc[0]
company = onee['company']
top_employer_by_country[c] = company
When we iterate over the unique values in countries, does ‘select_rows’ group the dataframe data according to the current iteration in ‘countries’ and store them as seperate dataframes? Also, when we have sorted the dataframe according to the ‘employees’ column, how does Pandas sort the employees while keeping the ‘country’ column grouped?
Can someone explain the for loop steps in detail.
Thank Youu