鉴于以下情况:
dd = {}
for i in range(3):
for j in range(3):
key = (f"col_{i}", j)
dd[key] = {1: 2, 3: 4}
print(pd.DataFrame.from_dict(dd))
看起来像:
col_0 col_1 col_2
0 1 2 0 1 2 0 1 2
1 2 2 2 2 2 2 2 2 2
3 4 4 4 4 4 4 4 4 4
我想使用以下替换:
reps = {
"col_0": {0: "o", 1: "one", 2: "two"},
"col_1": {0: "o2", 1: "one2", 2: "two2"},
"col_2": {0: "o3", 1: "one3", 2: "two3"},
}
因此col_0, col_1,col_2不变,但第二层 分别0,1,2更改为o, one, two, o2, one2, two2, 和o3, one, two3 ,给出类似的内容:
col_0 col_1 col_2
o one two o2 one2 two2 o3 one3 two3
1 2 2 2 2 2 2 2 2 2
3 4 4 4 4 4 4 4 4 4
阿波罗的战车
相关分类