Python CSV read, write and indexing -
this question has reply here:
inline csv file editing python 2 answersi using python 3.4.1 , new it:
i wanting read , write same csv file in python. want able index or search name , info (height , age) person. have little no thought on how help appreciated. here code (or lack of it, far):
import csv def addperson(): name = input("name: ") age = input("age: ") height = input("height: ") open('file.csv', 'wb') f: author = csv.writer(f) writer.writerows(name,age,height) open('file.csv', 'rb') f: reader = csv.reader(f) row in reader: print row addperson():
it ideal if explain on how add together more 1 person too. in advance.
(p.s i'm getting errors trying run code.)
you should utilize pandas library. create info frame csv file df = pandas.from_csv('file.csv')
once have info frame, can add together rows df.append()
, take list
to search in df df.query()
once you're done can save csv file withdf.to_csv('file.csv')
python csv search indexing
No comments:
Post a Comment