I would like to find a value of column A base on column B's condition. for example, find the ts of first 'B' from value columns:
import pandas as pd
data = [[10,"A"],[20,"A"],[30,"B"],[40,"B"]]
df = pd.DataFrame(data,columns=['ts','value'])
print(df)
: ts value
: 0 10 A
: 1 20 A
: 2 30 B
: 3 40 B
I would like to print out 30 for this example!
CodePudding user response:
You can do that with slice
df.loc[df['value'].eq('B'),'ts'].iloc[0]
Out[163]: 30