xxxxxxxxxx
# importing the pandas library
import pandas as pd
# reading the csv file
df = pd.read_csv("AllDetails.csv")
# updating the column value/data
# df is a file, loc is a code to finde element in csv file, inside of []: 5 is a row and
# 'Name' is a column
df.loc[5, 'Name'] = 'SHIV CHANDRA'
# writing into the file (rewrite csv file)
df.to_csv("AllDetails.csv", index=False)
print(df)
# so if in your csv file at row 5 and column 'Name' data was Kallem Kruthik now its
# gonna be SHIV CHANDRA
xxxxxxxxxx
import csv
f=open('student2.csv','r')
a=csv.reader(f)
l=[]
print("current data")
for i in a:
l.append(i)
print(i)
f.close()
jj=0
b=str(int(input("Roll no of student::")))
for i in l:
if b==str(i[0]):
print(""".
what would you like to change
1.Name
2.Marks
3.exit""")
c=int(input("::"))
if c==1:
d=input("new name::")
i[1]=d
elif c==2:
e=int(input("new marks::"))
i[2]=e
elif c==3:
exit
jj+=1
if jj==0:
print("no such kid")
with open ('student2.csv','w',newline='') as f:
g=csv.writer(f)
g.writerows(l)