In this article you will get some some important programs for Data transfer CSV to dataframe class 12. These programs can be used to your board practical file.
Data transfer CSV to dataframe class 12 IP
Write a program to do the following:
[1] Read player details like player name and score
import pandas as pd
def player_data():
l = []
player_name=input(“Enter Player Name:”)
score = int(input(“Enter individual score:”))
l.append([player_name,score])
df=pd.DataFrame(l)
df.to_csv(‘D:\\Python\\CSV\\CSV 2 DF\\Player.csv’)
player_data()
[2] Read customer details like customer name, city, contact number (use proper headers in the CSV file).
To give proper headers use dictionary to store data.
import pandas as pd
def data_csv():
cust_name=input(“Enter Customer Name:”)
city=input(“Enter city:”)
cn=input(“Enter Contact Number:”)
n=input(“Enter index value:”)
cust_dic={‘Name’:cust_name,’City’:city,’Contact No’:cn}
df=pd.DataFrame(cust_dic,index=[n])
df.to_csv(‘D:\\Python\\CSV\\CSV 2 DF\\customer.csv’)
data_csv()
[3] Read students details like rollno, name, English, Maths, Physics, Chemistry and IP subject marks. (Avoid automatic index in CSV file)
import pandas as pd
def data_csv():
rno=int(input(“Enter Roll No:”))
sname=input(“Enter Student Name:”)
eng=int(input(“Enter English:”))
maths=int(input(“Enter Maths Marks:”))
phy=int(input(“Enter Physics Marks:”))
che=int(input(“Enter Chemistry Marks:”))
IP = int(input(“Enter IP Marks:”))
idx=int(input(“Enter the index value”))
stud_dic={‘Roll No’:rno,’Student Name’:sname,’English’:eng,
‘Maths’:maths,’Physics’:phy,’Chemistry’:che,’IP’:IP}
df=pd.DataFrame(stud_dic,index=[idx])
df.to_csv(‘D:\\Python\\CSV\\CSV 2 DF\\students.csv’, index=False)
data_csv()
You can use while loop and enter more records.
[4] Read details of banks like IFSC code, branch name, city, and pin code and branch manager name
Do yourself
[5] Read following CSV file and store the contents into datafame and display on the scree:
SNo Batsman Runs Balls 1 K L Rahul 30 22 2 S Dhawan 52 36 3 Virat Kohli 40 24 4 Sanju Samson 15 10 5 Hardik Pandya 42 22 6 Shreyas Iyer 12 5
import pandas as pd
def data_csv():
df=pd.read_csv(‘D:\Python\CSV\CSV 2 DF\T20I_IND_AUS.csv’)
print(df)
data_csv()
For other CSV functions click here.
Transfer Data into CSV files
Click here to read notes to understand the concept CSV to dataframe class 12 in well manner.
Notes Data Transfer to CSV
Download the code and CSV files used in this practical for CSV to dataframe class 12 from below given link.
Like this: Like Loading...
Related
Post navigation