top of page
learn_data_science.jpg

Data Scientist Program

 

Free Online Data Science Training for Complete Beginners.
 


No prior coding knowledge required!

Pandas Technique: Sorting Dataset

Writer's picture: Abu Bin FahdAbu Bin Fahd

import pandas as pd
import numpy as np

Read Dataset

df = pd.read_csv('Srt_dta.csv')
df

Sorting

Pandas sort_values() function sorts a data frame in Ascending or Descending order of passed Column. It's different than the sorted Python function since it cannot sort a data frame and particular column cannot be selected.

df.sort_values('Weight(kg)')

Sorting in descending value

To sort in descending order, we need to specify ascending=False

df.sort_values('Weight(kg)', ascending=False)

Sorting by multiple variables

Call pandas.DataFrame.sort_values(by, ascending) with by as a list of column names to sort the rows in the DataFrame object based on the columns specified.

df.sort_values(['Weight(kg)', 'Height(cm)'])

Sorting by multiple variables

Call pandas. DataFrame. sort_values(by, ascending) with by as a list of column names to sort the rows in the DataFrame object based on the columns specified in by . Set ascending to a tuple of booleans corresponding to the columns in by , where True sorts in ascending order and False sorts in descending order.

df.sort_values(['Weight(kg)', 'Height(cm)'], ascending=[True, False])


0 comments

Recent Posts

See All

Comments


COURSES, PROGRAMS & CERTIFICATIONS

 

Advanced Business Analytics Specialization

Applied Data Science with Python (University of Michigan)

Data Analyst Professional Certificate (IBM)

Data Science Professional Certificate (IBM)

Data Science Specialization (John Hopkins University)

Data Science with Python Certification Training 

Data Scientist Career Path

Data Scientist Nano Degree Program

Data Scientist Program

Deep Learning Specialization

Machine Learning Course (Andrew Ng @ Stanford)

Machine Learning, Data Science and Deep Learning

Machine Learning Specialization (University of Washington)

Master Python for Data Science

Mathematics for Machine Learning (Imperial College London)

Programming with Python

Python for Everybody Specialization (University of Michigan)

Python Machine Learning Certification Training

Reinforcement Learning Specialization (University of Alberta)

Join our mailing list

Data Insight participates in affiliate programs and may sometimes get a commission through purchases made through our links without any additional cost to our visitors.

bottom of page