在Python

时间:2017-04-20 23:47:23

标签: python

我已经完成了分析,并使用result.to_frame()将结果转换为数据框。结果如下:

enter image description here

下一步是根据第1列构建关键表并对计数求和。为了做到这一点,我想将第一列标记为" query"。我使用了这段代码,但第一列无法重命名。

df.rename(columns = {'query':'sum of counts'}, inplace = True)

我发现它显示这个数据框只有一列,即使我看到两个。

enter image description here

1 个答案:

答案 0 :(得分:0)

看起来你确实有1列,描述实际上是你的索引。如果您的DataFrame是“df”,请尝试以下操作:

df.shape # this should show (N, 1) where N is the number of records
df['Query'] = df.index # to pull a copy of the index into a column

然后你应该能够正常进行。