熊猫为表创建DF

时间:2020-06-19 21:51:58

标签: pandas format callable

我正在尝试创建表,但首先创建了具有该表所需元素的DF,然后出现此错误:

File "<ipython-input-400-241c1509eba9>", line 4, in <module>
[c1.iloc[:,1]],

TypeError: 'module' object is not callable

这是我用来创建新DF“ c1t”的命令:

c1t = pd({
"Range": ["50-75%", "75-90%", "90-110%",
"110-125%","125-150%"],"adjusted_power": [c1.iloc[:,0]],"counts":
 [c1.iloc[:,1]],
}).set_index("Range")

这是DF“ c1”:

       adjusted_power  counts
0   (9694.2, 14541.2]       2
1  (14541.2, 17449.5]       3
2  (17449.5, 21327.2]      20
3  (21327.2, 24235.4]       3
4  (24235.4, 29082.5]       1

type(c1)
Out[412]: pandas.core.frame.DataFrame

我假设DF“ c1”是可调用的,因为我收到可调用错误,所以我的假设必须为false,但是我不确定如何为新DF(c1t)包括“ c1”。

1 个答案:

答案 0 :(得分:0)

要创建与c1t相同的新数据框c1,但可以为其分配索引(返回副本)并在该副本上设置索引:

c1t = c1.set_index(pd.Index(["50-75%", "75-90%", "90-110%","110-125%","125-150%"], name='Range'))