Pandas(python):如何将列添加到dataframe的索引? [英] Pandas (python): How to add column to dataframe for index?
本文介绍了Pandas(python):如何将列添加到dataframe的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在数据框中有30个行的索引具有以下形式:
The index that I have in the dataframe (with 30 rows) is of the form:
Int64Index([171, 174,173, 172, 199..............
....175, 200])
索引没有严格增加,因为数据框是sort()的输出。
我想添加一个系列列:
The index is not strictly increasing because the data frame is the output of a sort(). I want to have add a column which is the series:
[1, 2, 3, 4, 5......................., 30]
我应该怎么做?
谢谢。
推荐答案
怎么样,
from pandas import *
idx = Int64Index([171, 174, 173])
df = DataFrame(index = idx, data =([1,2,3]))
print df
gives me,
0
171 1
174 2
173 3
这是你在找什么?
这篇关于Pandas(python):如何将列添加到dataframe的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文