为什么两个数据帧的 pd.concat() 会导致 FutureWarning:连接 bool-dtype 时的行为?

V.N*_*uri 9 python pandas

项目清单

我想连接两个数据框,pd.concat()如下所示:

if (not df_1.empty) | (not df_2.empty):
    new_df= pd.concat([df_1, df_2]) 
Run Code Online (Sandbox Code Playgroud)

它返回以下警告:

FutureWarning: Behavior when concatenating bool-dtype and numeric-dtype arrays is deprecated; in a future version these will cast to object dtype (instead of coercing bools to numeric values). To retain the old behavior, explicitly cast bool-dtype arrays to numeric dtype.
Run Code Online (Sandbox Code Playgroud)

我也读过这个DataFrame问题,但这里我有一个包含str不同类型的数字(intfloat)。这种情况我该怎么办?

这是每个数据帧的样本数据:df_1:

约会时间 进入率 停止 限制 数量 标准批次 货币名称
2022年3月11日 11:24 1.31006 0 0 5000 0.05 英镑兑美元 真的
2022年3月11日 11:24 1.31007 0 0 1000 0.01 英镑兑美元 错误的
2022年3月11日 11:11 1.79134 0 1.78448 2000年 0.02 GBPAUD 真的

df_2:

约会时间 进入率 停止 限制 数量 标准批次 货币名称
2022年3月14日 10:24 1.31012 0 0 5000 0.05 英镑兑美元 错误的
2022年3月11日 12:25 1.31017 0 0 3000 0.09 欧元兑美元 错误的
2022年3月14日 10:00 1.79114 0 1.78448 2000年 0.03 澳元CAD 真的

Emi*_*son 5

当连接所有包含相同列且跨帧数据类型一致的数据帧列表时,我在意外位置收到此警告。出现警告的原因是某些帧有 0 行,因此没有以与其他帧相同的方式分配数据类型。在连接之前过滤掉空数据帧后,我停止接收错误。