小编the*_*son的帖子

将新的字典值列添加到 Pandas 数据框

这样做的目的是将这两个结构合并在一起: 1. 键值对字典(string1 : string2)——称之为 c_dict。2. Pandas DataFrames,其中一列包含 c_dict.keys() 的子集。让我们将此数据帧称为 c_df。

我希望最终的结构是一个 DataFrame,其中字典中的字符串 2 作为额外的列添加到 c_df。

例如:

    c_dict = { 'A' : 'aaa', 'B' : 'bbb', 'C' : 'ccc' }
    print(c_df)

      col1 col2 col3
     0 A    43   55
     1 B    59   88
Run Code Online (Sandbox Code Playgroud)

然后最终产品将是:

       col1 col2 col3 col4
     0  A    43   55  aaa
     1  B    59   88  bbb  
Run Code Online (Sandbox Code Playgroud)

python merge dictionary data-structures pandas

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

标签 统计

data-structures ×1

dictionary ×1

merge ×1

pandas ×1

python ×1