Python Forum

Full Version: Sorting table data
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi everyone,

I've a difficulties with my project, I'm a novice in Python. I would like sort my column "TypeDOC" in descending order but it's not possible because of my index I think. Would you have an idea to solve my problem ?

df3 = pd.DataFrame(data=list(liste01.typeconsultation), index=liste01.iddoc, columns=['TypeDOC'])
df3 = df3[df3['TypeDOC'] == 'document']
df3['IdDOC'] = df3.index

tableau4 = pd.pivot_table(df3, index='IdDOC', values='TypeDOC', aggfunc='count')
tableau4.sort_values(by = 'TypeDOC')
tableau4
Thanks to all those who will take the time to answer me !
Hi @Blacktime2 ,
Welcome to the forum. You are not very clear in describing what goes wrong. Do you get an error message? Is te result not as expected?

When reading the manual of DataFrame.sort_values(by, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last', ignore_index=False, key=None) I see there is a parameter "inplace". If that parameter is False (default) the method returns a sorted dataframe. If you want to sort "tableau4", then add parameter "inplace=True".