尝试返回列匹配另一个数组值的数组行。
我从elm
值开始,并调用nearby
函数,根据elm
表搜索df
附近的其他榆树。函数返回像这样的结果(所有int):
C1 C2 C3 C4
0 100 20 11 1
所以我需要从满足两个条件的elm_data_table
中提取信息:
1)LC-col
列中的值与LC
值匹配
2)ELM
列中的值必须与other_elm
我期待来自elm_data_table
的4行数据,因为我试图找到4个值的数据
任何提示?
import panda as pd
#df and elm_data_table are Panda dataframes
def nearby(elm, df):
return df[df['ELM'] == elm].iloc[:,5:9]
elm = 1000
LC = 200
other_elm = nearby(elm, df)
other_elm_info = elm_data_table[(elm_data_table['LC-col'] == LC) & (elm_data_table['ELM'] == other_elm )]
答案 0 :(得分:1)
你的意思是这样吗?
import pandas as pd
import numpy as np
df = pd.DataFrame({ 'A' : 1.,
'B' : pd.Timestamp('20130102'),
'C' : pd.Series(1,index=list(range(4)),dtype='float32'),
'D' : np.array([3] * 4,dtype='int32'),
'E' : pd.Categorical(["test","train","tot","toast"]),
'F' : 'foo' })
elms=['test','train']
df[df.E.isin(elms)]