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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using pyodbc&pandas to load a Table data to df tester_V 3 746 Sep-09-2023, 08:55 PM
Last Post: tester_V
  panda table data kucingkembar 0 1,073 Mar-01-2022, 10:38 PM
Last Post: kucingkembar
  Strategy on updating edits back to data table and object variables hammer 0 1,163 Dec-11-2021, 02:58 PM
Last Post: hammer
  SQLALCHEMY - Not selecting data from table jamesaarr 4 2,178 Nov-02-2021, 03:02 PM
Last Post: Larz60+
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,113 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Need help on extract dynamic table data Dr_Strange 0 2,446 Apr-30-2021, 07:03 AM
Last Post: Dr_Strange
  Load the data from multiple source files to one table amy83 2 2,521 Apr-27-2021, 12:33 AM
Last Post: Pedroski55
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 7,559 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt
  Sorting data pprod 4 2,613 Feb-01-2021, 06:51 PM
Last Post: paul18fr
  Data extraction from a table based on column and row names tgottsc1 1 2,356 Jan-09-2021, 10:04 PM
Last Post: buran

Forum Jump:

User Panel Messages

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