Difference Between loc() and iloc() in Pandas

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

Program 1

Pandas Dataset

# loc and iloc methods
import pandas as pd
myfile="D://mypandas/employee1.xlsx"
df=pd.read_excel(myfile)
print(df.loc[5,'empname'])





# m=int(input("Enter starting index value: "))
# n=int(input("Enter ending index value: "))
#print(df.iloc[m:n,[1,4]])
#print(df.iloc[m:n,[1,2,3]])

# m=int(input("Enter index value: "))
# print(df.iloc[m,[1,4]])
# m=int(input("Enter starting index value: "))
# n=int(input("Enter ending index value: "))
# #print(df.loc[1:5])
# print(df.loc[m:n,'empname'])
# n=int(input("Enter index value: "))
# #print(df.loc[n,['empname','totalsalary']])

 

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback 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 *