0% found this document useful (0 votes)
15 views2 pages

CSV DataFrame Operations in Python

The document outlines a series of tasks to be performed on a CSV file named 'Student_result.csv' using Python's Pandas library. It includes operations such as displaying specific columns, modifying data, creating a duplicate file, and filtering students based on their percentage. The document also provides code snippets for each task to facilitate the operations.

Uploaded by

kavyagandhit
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

CSV DataFrame Operations in Python

The document outlines a series of tasks to be performed on a CSV file named 'Student_result.csv' using Python's Pandas library. It includes operations such as displaying specific columns, modifying data, creating a duplicate file, and filtering students based on their percentage. The document also provides code snippets for each task to facilitate the operations.

Uploaded by

kavyagandhit
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CSV programs for practical file

Q1) Read the ‘Student_result.csv’ to create a data frame and do the following
operation:

# To display Adm_No, Gender and Percentage from ‘student_result.csv’ file.

# To display the first 5 and last 5 records from ‘student_result.csv’ file.

Q2) Read the ‘Student_result.csv’ to create a data frame and do the following
operation:
# To display Student_result file with new column names.
# To modify the Percentage of student below 40 with NaN value in dataframe.

Q3) Read the ‘Student_result.csv’ to create a data frame and do the following
operation:
# To create a duplicate file for ‘student_result.csv’ containing Adm_No, Name and
Percentage.
# Write the statement in Pandas to find the the students got more than 80
percentage and also print student’s Adm No, Student’s name and Percentage.
import pandas as pd
import numpy as np
import csv
# To create a duplicate file for ‘student_result.csv’ containing Adm_No, Name and
Percentage.
df1 = pd.read_csv('d:\\student_result.csv')
df1.to_csv('d:\\
copyStudent_result.csv',columns=['ADM_NO',"STUDENT'S_NAME","PERCENTAGE
"])
# Display Copied Dataframe
#df2=pd.read_csv('d:\\copyStudent_result.csv')
print(df2)
# find and print the student’s name and percentage who are having percentage
more than 80
print(df1[df1['PERCENTAGE']>80])

Common questions

Powered by AI

Pandas provides robust methods for data manipulation, such as filtering with conditions, merging datasets, and generating new data frames, which facilitate comprehensive educational data analysis. It is particularly beneficial for educators needing to manage and process large volumes of student data efficiently .

Identifying students with over 80% helps in recognizing academic excellence and planning relevant educational interventions or rewards. Using Pandas, this can be achieved through boolean indexing: df[df['PERCENTAGE'] > 80] to filter and then display the desired information .

Using Pandas, you can display the first five records with the head() function and the last five records with the tail() function after reading the CSV file into a data frame .

Operations on 'Student_result.csv' using Pandas include displaying specific columns like Adm_No, Gender, and Percentage; modifying percentage values below 40 to NaN; creating a duplicate file; and identifying students with over 80% by name and Adm No .

Creating a duplicate CSV is useful for backup, sharing specific data excerpts, or preserving an original dataset while making modifications. Pandas streamlines this with the to_csv() method, allowing selection of specific columns or data transformations before saving .

You can modify specific entries in a Pandas data frame by applying conditions using boolean indexing. For instance, to modify student percentages below 40 to NaN, you would apply a conditional statement that sets those cells to Pandas' np.nan .

The function used is pd.read_csv(), and it is applied by specifying the file path as an argument. For instance, reading 'Student_result.csv' into a data frame would be done using df = pd.read_csv('d:\student_result.csv').

Modifying student data based on criteria, such as setting low percentages to NaN, helps focus analysis on relevant data and cleanses datasets for more accurate statistical appraisal. This ensures that outliers or irrelevant data do not skew overall educational performance insights .

Renaming columns can be done using the rename() function. It becomes necessary when original column names are not intuitive or standardized, hindering readability and analysis. This step enhances data consistency and aids in clear communication of data insights .

To create a duplicate CSV file with selected columns, you would first read the original CSV into a data frame. Then, use the to_csv() function, specifying the file path and columns to include. For example, creating a file with Adm_No, Name, and Percentage only .

You might also like