Sorting in Pandas

Get Job-Ready: Data Analysis using Python with 70+ Projects Start Now!!

Program 1

Pandas Dataset

# Sorting 
import pandas as pd
myfile="D://mypandas/employee.xlsx"
df=pd.read_excel(myfile)
#print(df)
#print(df.sort_index(ascending=True))
#print(df.sort_values(['empname'],ascending=False))
#print(df.columns)
#print(df.sort_values('totalsalary'))

Program 2

# Duplicate 
import pandas as pd
myfile="D://mypandas/employee.xlsx"
df=pd.read_excel(myfile)
print("Before Remove: ")
print(df.duplicated())
print(df.size)
print("------------------------------------------------")
df.drop_duplicates(inplace=True)
print("After Remove: ")
print(df.duplicated())
df.to_excel("D://mypandas/employeenewdata.xlsx")
print("..................Success...........")
# df1=df.drop_duplicates()
# print("After Remove: ")
# print(df1.duplicated())
# print(df1.size)
#print(df)

 

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *