11/8/25, 10:03 PM CSV file programs pandas
ChatGPT Log in Sign up for free
5 programme on csv file in pandas class 12
Sure! Here are 5 simple Python programs using Pandas that are commonly taught in
Class 12 Computer Science (CBSE) for working with CSV files. Each program reads data
from a CSV file and performs some operation.
📘 Program 1: Read and Display a CSV File
python Copy code
import pandas as pd
# Read CSV file
df = pd.read_csv('[Link]')
# Display the entire DataFrame
print("Contents of the CSV file:")
print(df)
✅ Explanation:
This program uses pd.read_csv() to read a CSV file named [Link] and prints its
contents.
[Link] 1/5
11/8/25, 10:03 PM CSV file programs pandas
📘 Program 2: Display First and Last Rows
python Copy code
import pandas as pd
df = pd.read_csv('[Link]')
print("First 5 rows:")
print([Link]())
print("\nLast 5 rows:")
print([Link]())
✅ Explanation:
[Link]() shows the first 5 rows.
[Link]() shows the last 5 rows.
You can also specify a number like [Link](3) to show only 3 rows.
📘 Program 3: Display Specific Columns
python Copy code
import pandas as pd
df = pd.read_csv('[Link]')
# Display only selected columns
[Link] 2/5
11/8/25, 10:03 PM CSV file programs pandas
print("Displaying Name and Marks columns:")
print(df[['Name', 'Marks']])
✅ Explanation:
Displays only the columns you specify, such as Name and Marks.
📘 Program 4: Filter Rows Based on a Condition
python Copy code
import pandas as pd
df = pd.read_csv('[Link]')
# Display students who scored more than 80
print("Students with marks greater than 80:")
print(df[df['Marks'] > 80])
✅ Explanation:
This filters rows where the column Marks has a value greater than 80.
📘 Program 5: Add a New Column and Save the CSV
python Copy code
import pandas as pd
df = pd.read_csv('[Link]')
[Link] 3/5
11/8/25, 10:03 PM CSV file programs pandas
# Add a new column 'Result' based on marks
df['Result'] = ['Pass' if m >= 33 else 'Fail' for m in df['Marks']]
# Save updated DataFrame to new file
df.to_csv('students_result.csv', index=False)
print("New file 'students_result.csv' created successfully!")
✅ Explanation:
Creates a new column Result based on marks.
Saves the modified data into a new CSV file.
🧾 Example [Link] file:
RollNo Name Marks
1 Aman 85
2 Neha 65
3 Raj 45
4 Tina 25
Would you like me to include output examples for these programs too? It’ll help you
understand what each one prints.
[Link] 4/5
11/8/25, 10:03 PM CSV file programs pandas
[Link] 5/5