r/pythonhelp • • 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

1 comment sorted by

2

u/Goobyalus Jul 15 '22

It's telling you df is a Series (not a DataFrame), and Series' sort_values method has no by argument like DataFrame's, the first argument is the axis. "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