12 Ip
12 Ip
NOTES
Class: XII Date: 08/07/2020
Subject: Topic:
Informatics Practices Importing/Exporting Data Between CSV Files/MySQL
and Pandas
Example :
import pandas as pd
df=pd.read_csv("C:\\Users\\Desktop\\covid19.csv")
“If the CSV file has some column headings but you don’t want to use them as
header”
Solution: Use skiprows argument with read_csv() function.
skiprows argument can either take a number for number of rows to be skipped from
beginning or it take
rd th th
A list of rows numbers to be skipped, e.g., to skip 3 , 5 and 7 rows write :
skiprows = [3,5,7]
So, to skip the default header and apply our own header row use the following code :
To set the Empno column as index label issue the following command at the prompt :
Answer :
import pandas as pd
Practice Question: Using the following CSV file create a dataframe with desired
column and print the highest salary value:
Empno Ename Desig Salary
0 2001 Tanisha Manager 23000
1 2002 Gaurav Programmer 20000
2 2003 Rajani Assistant 18000
3 2004 Lokesh Clerk 15000
4 2005 Anjali Clerk 16000
D7 = pd.read_csv("E:\online Classes July2020\\Employee.csv",
names=["EmpID","Name","Desig","Sal"], skiprows=1)
>>> D7
EmpID Name Desig Sal
0 2001 Tanisha Manager 23000
1 2002 Gaurav Programmer 20000
2 2003 Rajani Assistant 18000
3 2004 Lokesh Clerk 15000
4 2005 Anjali Clerk 16000
>>> print("The Maximum Salary is :",D7.Sal.max())
The Maximum Salary is : 23000