0

I have a csv file datasheet.csv -

City  A  B  C  D  E  F  G  H  I  J
1     -----------VALUES------------       
2     -----------VALUES------------   
3     -----------VALUES------------   
4     -----------VALUES------------ 
5     -----------VALUES------------
6     -----------VALUES------------     

Right now I store this with this code.

import pandas as pd
df = pd.read_csv('datasheet.csv') 

I am able to call columns with.

df['City'],df['G']

But im not so sure on how to procede with rows. Right now I have the code.

(df.loc[df['City']=='1'])

This prints the rows but im not able to use index to get any spesific value. For example when I do

print((df.loc[df['City']=='1'])[0])

It returns a error "key error: 0". Im not sure how to procede from here

Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58
Wiz Ninja
  • 19
  • 1
  • 5
  • 1
    You can directly use `df.loc[0]` or `df.loc[1]` for accessing rows by `index`. – Mayank Porwal Feb 06 '22 at 05:43
  • Hmm, yea I did that originally but I was wondering if there was a more efficient way to do it. – Wiz Ninja Feb 06 '22 at 05:48
  • 1
    `df.loc` is as efficient as it gets. Maybe if there's something really specific that you are trying to do, update the question with exact requirement, sample input and expected output in that case. – Mayank Porwal Feb 06 '22 at 05:50

0 Answers0