Help reading csv files | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Help reading csv files

I have to read a csv files which headers are "capital", "mar high", "other stuff" in "capital" there are cities in each row like say Texas then "mar high" = 321 and there are more data in other rows about Texas with different mar heights.... Well, I need to read each data corresponding to "Texas" is Texas a capital? Idk it's just an example :P I was trying to do this with the csv module and using .DictReader() was I too lost? :,D

15th Jun 2021, 3:49 AM
Jace🎭
Jace🎭 - avatar
3 Answers
15th Jun 2021, 4:02 AM
Sâñtôsh
Sâñtôsh - avatar
+ 1
import pandas as pd df=pd.read_csv('file.csv',index='capital') print(df.loc['Texas'])
16th Jun 2021, 4:33 AM
Akshay Urs M
Akshay Urs M - avatar
0
I think I can do what I want with an if statement like if row["capital" ] =="Texas": I'm trying that
15th Jun 2021, 4:15 AM
Jace🎭
Jace🎭 - avatar