简体   繁体   English

加入索引的Pandas正在为右侧DataFrame生成所有NaN

[英]Pandas joining on index is producing all NaN for right-side DataFrame

I am trying to join two pandas DataFrames on index. 我想在索引上加入两个pandas DataFrames。 The both have the same number of rows and everything about the index appears to be correct. 两者具有相同的行数,并且关于索引的所有内容看起来都是正确的。 However, when I run the code, 但是,当我运行代码时,

df1=df2.join(df3)

iIt produces all NaN for df3's values. i为df3的值生成所有NaN。 I have been searching google for a while now and have no idea why. 我一直在谷歌搜索一段时间,不知道为什么。

I have tried casting into pandas data frames and also reset_index. 我已经尝试过投射到pandas数据帧以及reset_index。 Neither did the trick. 这个伎俩也没有。

df1=df2.join(df3)

producing all NaN for df3's columns 为df3列生成所有NaN

In the expected results the NaN's would all have the values of df3. 在预期的结果中,NaN都将具有df3的值。 The actual results are producing all NaN. 实际结果是产生所有NaN。

My answer to this was to change the index types on both my dataframes. 我的答案是改变我的两个数据帧上的索引类型。 In my particular instance I converted to string. 在我的特定实例中,我转换为字符串。 Thanks! 谢谢!

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

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