Beginner stuck on Pandas GroupBy/Series/DF

Viewed 30

First day working with Pandas and need help figuring out how I'm going to get the min/max for job salaries for this exercise.

I've managed to group the columns 'job_title' and 'salary_in_usd' and calculate the mean of the latter. Now I want to calculate which job salary mean was highest, and which was lowest.

I was told that, because my data is now in a Series, I should convert it into a csv then back into a data frame - that way I can access the column for all salary_in_usd and calculate the min/max.

But for some reason when I convert it to a data frame and run d this

test = df_two.loc[:,['job_title', 'salary_in_usd']]

it gives me a Key Error saying "None of [Index(['job_title', 'salary_in_usd'], dtype='object')] are in the [columns]"

So not sure where I'm messing up here.

my code:

check = df.groupby(['job_title', 'salary_in_usd' ])['salary_in_usd'].mean()

df_av = check.to_csv()

with open('check.csv', 'w', newline ='') as f:
    writer = csv.writer(f)
    writer.writerow([df_av])

df_two = pd.read_csv('check.csv')

test = df_two.loc[:,['job_title', 'salary_in_usd']]
print(test)

0 Answers
Related