[英]How can I join two dataframes with different dtypes?
I have a dataframe(df1) with index as a date range and no columns specified and another dataframe(df2) with float values in every column. 我有一个数据框(df1),索引作为日期范围,没有指定列,另一个数据框(df2)在每列中都有浮点值。 I tried joining a specific column from df2 to df1 using .join() method and ended up with all values as NaN in df1.
我尝试使用.join()方法将特定列从df2连接到df1,最后在df1中将所有值作为NaN。 What should I do to solve this?
我该怎么做才能解决这个问题?
It's unclear what you mean without any example of the data or their shape, and without more details about what kind of 'join' you're trying to do. 如果没有任何数据或形状的例子,并且没有关于你正在尝试做什么样的“加入”的更多细节,目前还不清楚你的意思。 It sounds like you are trying to concatenate dataframes without relying on a column or index level names to join on.
听起来您正在尝试连接数据帧而不依赖于要加入的列或索引级别名称。 That's what
join
or merge
try to do, so if you don't have common values on the on
parameter of the join
, you'll end up with nan
s. 这就是
join
或merge
尝试这样做,所以如果你没有共同的价值观对on
的参数join
,你会最终nan
秒。 If I'm correct and you just want a concatenation of dataframes, then you can use concat
. 如果我是正确的,你只想要连接数据帧,那么你可以使用
concat
。 I can't provide the code without more details, but it would look something like this: 我不能提供没有更多细节的代码,但它看起来像这样:
new_df = pd.concat([df1, df2[['whatever_column_you_want_to_concatenate']]], axis=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.