[英]Pandas dataframe join on all elements
I am trying to join two dataframes in pandas.我正在尝试在 pandas 中加入两个数据帧。 One dataframe contains URLs in a column, which contains duplicates ( same values repeating).
一个 dataframe 在一列中包含 URL,其中包含重复项(相同的值重复)。
Second dataframe contains some properties of those URLs, but unique URLs only, no duplicates.第二个 dataframe 包含这些 URL 的一些属性,但只有唯一的 URL,没有重复。
I am trying to map back or join two dataframes where I get those properties of URLs in 1st dataframe, for all occurances of the URls.我正在尝试返回 map 或加入两个数据帧,我在第一个 dataframe 中获取 URL 的这些属性,以获取所有出现的 URls。
How can this be achieved?如何做到这一点? Which particular join |
哪个特别加盟| concatinate |
连接 | or merge method to use to combine the dataframes on all rows.
或合并方法用于组合所有行上的数据框。
The dataframe above is just example, actual dataframe has like 300+ unique URLs, and 1st dataframe has 10000+ rows.上面的 dataframe 只是示例,实际的 dataframe 有 300 多个唯一 URL,第一个 dataframe 有 1000 行。
I have tried inner join and outer join, does not works.我试过内连接和外连接,都不行。
Here's a working example that should be directly applicable.这是一个应该直接适用的工作示例。
import pandas as pd
df = pd.DataFrame(zip([1,2,3,2,3,1],[7,8,9,10,11,12]),columns=["A","B"])
print(df)
df2 = pd.DataFrame(zip([1,2,3],["foo","baz","bar"]),columns=["A","X"])
print(df2)
df3 = df.join(df2.set_index('A'), on='A')
print(df3)
You will use somthing like dataframe1.join(dataframe2.set_index("url"),on="url")
您将使用类似
dataframe1.join(dataframe2.set_index("url"),on="url")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.