0

Trying to do same parsing from csv file.

1  Xe   Xe   Xe   Xe   Xe    Zi   Zi   Zi   Zi    Zi
2  A    B    C    D    WOW   E    F    G    L    WOW
3
4
5                      data                     data2
6

trying to parse "data at index 5 and column WOW. So i tried

df = pd.read_csv("wow.csv", index_col=0, header=1)

data = df.loc[5, 'WOW']

it's actually working but just giving me data of first WOW not second or third... how can I loop and take all WOW's data?

3 Answers3

1

Using df.loc

df.loc[5,df.loc[2]=='WOW']
BENY
  • 317,841
  • 20
  • 164
  • 234
0
from pandas import DataFrame, read_csv
import pandas as pd

file = 'a.csv'
df = pd.read_csv(file)
for data in df.iterrows():
    print(data)

a.csv

Names,Highscore
Mel,8
Jack,5
David,3
Peter,6
Maria,5
Ryan,9
Fred
  • 314
  • 2
  • 7
0

I'm 95% certain that the data from your second and third WOW columns were lost as soon as you read them into your DataFrame.

Pandas read_table with duplicate names

https://github.com/pandas-dev/pandas/issues/9424

You'll have to find a different way to read in the file...

EDIT

People keep posting solutions for how to find the data when WOW is part of the column data, but the OP's code includes header=1 in the pd.read_csv, so the problem is that WOW becomes the column index. You cannot have two columns with the same index. I'd comment this on the posts if only I had enough reputation points to do so...

EDIT 2

Okay, that was a brain cramp, between us we had the full answer: the solution to OP's problem is 1) get rid of header=1 in the pd.read_csv call, i.e. get those WOWs out of the column header, and then 2) use the solution posted by @Wen-Ben, which will work once this modification is made.

Mr. Snrub
  • 322
  • 2
  • 13