简体   繁体   English

查找数据框中两列的交集

[英]Find intersection of two columns in a dataframe

I have a dataset with two columns, one has area names and one has timings.我有一个包含两列的数据集,一列有区域名称,一列有时间。 I have found the topmost frequently occurring area names as well as times.我找到了最常出现的地区名称和时间。 Now, I wish to find how many times, these two occur together, as in how many times do I have a frequently occurring name and a frequently occurring time in the same row.现在,我想知道这两者同时出现了多少次,比如我有多少次在同一行中有一个频繁出现的名字和一个频繁出现的时间。

I tried this but didn't work:我试过这个但没有用:

a = (3,1,93,34,29) #topmost frequntly occurring areas 
b = (8,9,17,18,7) #topmost frequently occurring timings (in 24 hr)

def update(df):
    for i in range(0,len(df)):
        if df.iloc[i,0] == any(a):
           if df.iloc[i,9] == any(b):
              arr1.append(df.iloc[i,:])

update(df)

it just gives an empty array:它只是给出一个空数组:

In [40]: arr1 Out[40]: []输入 [40]: arr1 输出 [40]: []

解决此问题的一种方法是仅提取包含出现频率最高的区域的行,然后从该数据子集中仅选择包含出现频率最高的行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM