[英]Finding matches in Panda DataFrame by matching a Panda DataFrame
嘗試返回一個數組的行,其中一列與另一個數組的值匹配。
我從elm
值開始,並根據搜索df
表調用nearby
函數在elm
nearby
查找其他elms。 函數返回如下結果(所有int):
C1 C2 C3 C4
0 100 20 11 1
因此,我需要從滿足兩個條件的elm_data_table
中提取信息:
1) LC-col
列中的值與LC
值匹配
2) ELM
列中的值必須與other_elm
中的4個值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 )]
你是這個意思嗎
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)]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.