我刚接触熊猫并尝试加入两个数据框:
第一个:
Date Id Provider
2019 1 Google
2019 2 Google
第二个:
Date-second Id-second Provider-second Test
2019-11 5 Bing True
2019-11 6 Bing True
我想要的输出看起来像这样:
Date Id Provider Date-second Id-second Provider-second Test
2019 1 Google 2019-11 5 Bing True
2019 2 Google 2019-11 6 Bing True
如果我使用pd.concat([df1,df2])
,则会在条目重叠的地方得到空值:
Date Date-DB Gclid Gclid_DB Provider Provider-DB click_type
0 2019-11-240 NaT EAIaIQobChMI2t6D4MqB5gIVA9bACh0BvwK-EAAYAyAAEg... NaN test2 NaN NaN
1 2019-11-240 NaT CjwKCAiAzuPuBRAIEiwAkkmOSJ7WSwoG9veQ-jKXYi5Fyx... NaN test2 NaN NaN
2 2019-11-240 NaT EAIaIQobChMIkdObncWB5gIVFZzVCh245Aq0EAAYASAAEg... NaN test2 NaN NaN
3 2019-11-240 NaT CjwKCAiAzuPuBRAIEiwAkkmOSHDEAo0jtVHXRWOr3Rh1Yj... NaN test2 NaN NaN
4 2019-11-240 NaT EAIaIQobChMI-ZenkNCB5gIVAx6tBh0gOg9GEAAYASAAEg... NaN test2 NaN NaN
... ... ... ... ... ... ... ...
12741 NaN 2019-11-25 23:59:40+00:00 NaN 7d904da7-cd77-428c-a0d3-1fbe3c3c992d NaN test2 gclid
12742 NaN 2019-11-25 23:59:44+00:00 NaN 690aa2e3-de06-4f96-82bc-aed9c7ed16dc NaN test2 gclid
12743 NaN 2019-11-25 23:59:45+00:00 NaN 7a3ebeee-bfad-4f9d-931c-234d30ad8b52 NaN test3 gclid
12744 NaN 2019-11-25 23:59:50+00:00 NaN 0e907d6f-0bf5-4fbc-8b03-8f0e0d73487b NaN test1 gclid
12745 NaN 2019-11-25 23:59:59+00:00 NaN 463bec78-b7c1-4a15-9f81-c163ece05a45 NaN test2 gclid
如果我使用axis=1
,则会出现以下错误:
pandas.core.indexes.base.InvalidIndexError: Reindexing only valid with uniquely valued Index objects
谢谢您的建议。