Write a program to import and export data between Pandas and CSV file with Practical Example.
1.To Export data between Pandas and CSV file
2.To Import data between Pandas and CSV file
- Write a program to Export data between dataframe and CSV with practical example
Program Logic:
- Import pandas module in program using import statement
- Import numpy module using import statement
- Create Dictionary object say ‘marks’ with different set of key-value pair
- Create DataFrame object say ‘result’ using DataFrame method and pass index as argument to it
- Print DataFrame ‘result’ using print function
- Write dataframe object into csv file using to_csv method and pass data frame object as an argument to it
Below is implementation code/Source code:
import pandas as pd
import numpy as np
marks = { "English" :[67,89,90,55],
"Maths":[55,67,45,56],
"IP":[66,78,89,90],
"Chemistry" :[45,56,67,65],
"Biology":[54,65,76,87]}
result = pd.DataFrame(marks,index=["Athang","Sujata","Sushil","Sumedh"])
print("******************Marksheet****************")
print(result)
result.to_csv("result.csv")
Below is Output:
*****************Marksheet**************** English Maths IP Chemistry Biology Athang 67 55 66 45 54 Sujata 89 67 78 56 65 Sushil 90 45 89 67 76 Sumedh 55 56 90 65 87
Below is Snapshot of executable code with output:


Below is result.csv file



2. Write a program to import data between pandas and CSV file with Practical Example
Program Logic:
- Import pandas module in program using import statement
- Read data from CSV file using read_csv method and pass CSV file say ‘result.csv” as an argument to it
- Store data which is read from CSV file in python object say ‘df’
- Display data as output using print function
Below is implementation code/Source code
import pandas as pd
# read data from CSV file
df = pd.read_csv("result.csv")
print(df)
Below is Output:
Unnamed: 0 English Maths IP Chemistry Biology 0 Athang 67 55 66 45 54 1 Sujata 89 67 78 56 65 2 Sushil 90 45 89 67 76 3 Sumedh 55 56 90 65 87
Below is Snapshot of executable code with output:


Below is result.csv file



You can also check this too:
- Write a program to import and export data between Pandas and CSV file.
- Write a program to analyze the performance of student on different parameters subject wise or class wise from the given school result data.
- Write a program to analyze and plot appropriate chart with title and legend for the data frame created above.
- Write a program to create pie chart of five most countries are affected by corona virus in 2020. Read the data from CSV file.
<