Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting table data
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')
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".

Possibly Related Threads…
Thread Author Replies Views Last Post
  panda table data kucingkembar 0 621 Mar-01-2022, 10:38 PM
Last Post: kucingkembar
  Strategy on updating edits back to data table and object variables hammer 0 802 Dec-11-2021, 02:58 PM
Last Post: hammer
  SQLALCHEMY - Not selecting data from table jamesaarr 4 1,520 Nov-02-2021, 03:02 PM
Last Post: Larz60+
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 1,569 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Need help on extract dynamic table data Dr_Strange 0 1,929 Apr-30-2021, 07:03 AM
Last Post: Dr_Strange
  Load the data from multiple source files to one table amy83 2 1,886 Apr-27-2021, 12:33 AM
Last Post: Pedroski55
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 5,741 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt
  Sorting data pprod 4 2,050 Feb-01-2021, 06:51 PM
Last Post: paul18fr
  Data extraction from a table based on column and row names tgottsc1 1 1,910 Jan-09-2021, 10:04 PM
Last Post: buran
  Problems Sorting Data in an External File (.txt) Superlegend21 1 3,295 Dec-27-2020, 10:06 PM
Last Post: Superlegend21

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020