import pandas as pd
d = {'col1': [1, 2,3,4], 'col2': [4,3,2,1]}
df = pd.DataFrame(data=d)
df
col1 col2
0 1 4
1 2 3
2 3 2
3 4 1
# a is the value in the first column and df is the data frame
def a2b(a,df):
return df[df.iloc[:,0]==a].iloc[0,1]
a2b(2,df)
通过使用df.iloc,您可以通过索引获得所需的行或列。 通过使用mask,您可以过滤数据帧以获得所需的行(其中列a==某个值),并通过df.iloc[0,1]获取第二列中的值
返回3
相关问题 更多 >
编程相关推荐