r/pythonhelp • u/[deleted] • Jul 15 '22
Sorting data frame by column value
Hi there,
if anyone could help me out that would be greatly appreciated. I have been searching this error on the internet for a bit and cannot find anything.
I have a data frame that I am trying to sort by the column "age_of_shooter"
code:
df.sort_values("age_of_shooter" )
I am getting this error:
ValueError: No axis named age_of_shooter for object type Series
4
Upvotes
2
u/Goobyalus Jul 15 '22
It's telling you
dfis aSeries(not aDataFrame), andSeries'sort_valuesmethod has nobyargument likeDataFrame's, the first argument is theaxis."age_of_shooter"is not an axis of a series.https://pandas.pydata.org/docs/reference/api/pandas.Series.sort_values.html
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sort_values.html