Python Forum

Full Version: Sorting a DataFrame - Best Practice?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I am using Jupyer and SQL magic to create a dataframe from my query:
df = query_from_magic.DataFrame()
I then wanted to look at a sub-set of that data. In this specific example, I want to probe into a given date and then sort the results based on the integer stored in the 'count' column:
df_check = df.loc[df.date == '2020-01-28'] 
df_check.sort_values(by='count', inplace=True, ascending=True)
df_check
I am getting the warning about SettingWithCopyWarning.

Is there a better approach to what I am trying to do? It doesn't make sense to me that I should create a copy of my new, filtered data frame to simply sort it..
Here' a good resource for you to understand SettingWithCopyWarning:
https://www.dataquest.io/blog/settingwithcopywarning/