Sort pandas DataFrame by Multiple Columns in Python (Example) | Order Rows | sort_values() Function

Publié le: 25 novembre 2022
sur la chaîne: Statistics Globe
728
14

How to order the rows of a pandas DataFrame based on multiple columns in the Python programming language. More details: https://statisticsglobe.com/sort-pand...
Python code of this video:

import pandas as pd # Import pandas library in Python

data = pd.DataFrame({'x1':range(0, 8), # Create example DataFrame
'x2':['C', 'A', 'B', 'C', 'A', 'A', 'B', 'A'],
'x3':['a', 'b', 'c', 'b', 'c', 'b', 'a', 'c']})
print(data) # Print example DataFrame

data_new = data.sort_values(['x2', 'x3']) # Sort DataFrame
print(data_new) # Print new DataFrame

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


Sur cette page du site, vous pouvez voir la vidéo en ligne Sort pandas DataFrame by Multiple Columns in Python (Example) | Order Rows | sort_values() Function durée heure minute seconde en bonne qualité , qui a été Téléchargé par l'utilisateur Statistics Globe 25 novembre 2022, Partagez le lien avec vos amis et connaissances, sur youtube cette vidéo a déjà été regardée 728 fois et il a aimé 14 téléspectateurs. Bon visionnage!