Pandas I Notes 06 - June 20
Pandas I Notes 06 - June 20
11 13
14
12
Importing CSV file to DataFrame
(Reading from a CSV file to Dataframe)
Steps:
1. Create a CSV file in MS Excel with data as follows:
Marks scored by 5 students in 3 subjects
2. Write Python program to import the data into data frames.
3. Display the imported data.
Importing CSV file to DataFrame
(Reading from a CSV file to Dataframe)
df=pd.read_csv(<Filepath>)
It loads data from excel file to Pandas dataframe.
Importing CSV file to DataFrame
To display all column labels
print(marks.columns)
To display one column label
print(marks.columns[1])
To display mean of a column
print(marks.iloc[:,1].mean())
Using iteration
for (col,colSeries) in marks.iteritems():
if col!="Name":
print(col,colSeries.mean())
Importing CSV file to DataFrame
Using iteration
Importing CSV file to DataFrame
Display all the attributes of the dataframe
Importing CSV file to DataFrame
Display the total marks, average marks of each student.