Answers for "Python sort dataframe by list"

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