【发布时间】:2019-04-26 18:54:34
【问题描述】:
我是 python 新手,我正在尝试从第一列中找到第二列中包含我正在搜索的所有条目的条目。例如:我想要条目 {155, 137} 并且我希望从 id1 列中获得 5 和 6 作为回报。
id1 id2
----------
1. 10
2. 10
3. 10
4. 9
5. 137
5. 150
5. 155
6. 10
6. 137
6. 155
....
我在谷歌上搜索了很多,但无法解决。我从 excel 中读取了这些条目,我尝试了多个 for 循环,但它看起来不太好,因为我正在搜索很多条目
我试过这个:
df = pd.read_excel('path/temp.xlsx') #now I have two Columns and many rows
d1 = df.values.T[0].tolist()
d2 = df.values.T[1].tolist()
d1[d2.index(115) & d2.index(187)& d2.index(276) & d2.index(239) & d2.index(200) & d2.index(24) & d2.index(83)]
它返回 1
我这周开始工作,所以我很新
【问题讨论】:
标签: python dataframe indexing row