Answers for "pandas column sort by list"

23

sort dataframe by column

df.sort_values(by='col1', ascending=False)
Posted by: Guest on April-30-2020
1

Python sort dataframe by list

# sorts the dataframe so resulting order of ColumnName matches order in list
df = df.set_index(ColumnName).reindex(list_to_sort_by).reset_index()
Posted by: Guest on June-06-2021

Python Answers by Framework

Browse Popular Code Answers by Language