小编V.N*_*uri的帖子

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

项目清单

我想连接两个数据框,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 英镑兑美元 …

python pandas

9
推荐指数
1
解决办法
7119
查看次数

python 如何合并集合列表并将它们作为集合返回?

我有一个这样的集合列表:

set_list = [{1, 2, 3}, {4, 5, 1, 6}, {2, 3, 6}, {1, 5, 8}]
Run Code Online (Sandbox Code Playgroud)

现在我想将所有集合合并在一起并返回所有集合的集合,如下所示:

final_set = {1, 2, 3, 4, 5, 6, 8}
Run Code Online (Sandbox Code Playgroud)

我已经使用了这段代码,但它无法正常工作:

tmp_list = []
final_set = set(tmp_list.append(elem) for elem in set_list)
Run Code Online (Sandbox Code Playgroud)

我应该怎么办?

python list set

4
推荐指数
1
解决办法
620
查看次数

如何根据字典键和值过滤pandas数据帧行?

我有一个 Python 数据框和一个字典,如下所示,我需要根据字典过滤数据框。如您所见,字典的键和值是数据帧的两列。我想要一个数据帧的子集,其中包含字典的键和值以及其他列。

df:

客户ID 类别 类型 送货
40275 真的
40275 软件 错误的
40275 电子游戏 错误的
40275 手机 错误的
39900 光盘/DVD 真的
39900 真的
39900 软件 真的
35886 手机 错误的
35886 电子游戏 错误的
35886 光盘/DVD 错误的
35886 软件 错误的
40350 软件 真的
28129 软件 错误的

字典是:

d = {
 40275: ['Book','Software'],
 39900: ['Book'],
 35886: ['Software'],
 40350: ['Software'],
 28129: ['Software']
 }
Run Code Online (Sandbox Code Playgroud)

我需要以下数据框:

客户ID 类别 类型 送货 …

python dictionary dataframe pandas

2
推荐指数
1
解决办法
3308
查看次数

标签 统计

python ×3

pandas ×2

dataframe ×1

dictionary ×1

list ×1

set ×1