项目清单
我想连接两个数据框,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不同类型的数字(int,float)。这种情况我该怎么办?
这是每个数据帧的样本数据:df_1:
| 约会时间 | 进入率 | 停止 | 限制 | 数量 | 标准批次 | 货币名称 | 买 |
|---|---|---|---|---|---|---|---|
| 2022年3月11日 11:24 | 1.31006 | 0 | 0 | 5000 | 0.05 | 英镑兑美元 … |
我有一个这样的集合列表:
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 数据框和一个字典,如下所示,我需要根据字典过滤数据框。如您所见,字典的键和值是数据帧的两列。我想要一个数据帧的子集,其中包含字典的键和值以及其他列。
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 | 类别 | 类型 | 送货 … |
|---|