MarkokraM
MarkokraM

Reputation: 990

Selecting data based on row index and cell value on Pandas

I have a dataframe (df):

    a   b   c   d
0   G1  G2  G3  G4
1   1   2   3   4

I'd like to get the whole column data based on certain cell index (0) and cell content (G3) value:

input:

search("G3", df, 0)

output something like:

["c", "G3", 3]

How would you do that?

Upvotes: 0

Views: 614

Answers (1)

waitingkuo
waitingkuo

Reputation: 93984

I suggest that you can transpose your dataframe first and then do some simple compares:

In [14]: df.T[df.T[0] == 'G3']
Out[14]: 
    0  1
c  G3  3

Upvotes: 1

Related Questions