合并多个Series为DataFrame并且重置索引

Posted 马蹄哒哒

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了合并多个Series为DataFrame并且重置索引相关的知识,希望对你有一定的参考价值。

a=[序号,1,2,3,4,5]
b=[成本,20,45,12,34,67]
import  pandas
c=pandas.Series(a)
d=pandas.Series(b)
e=pandas.DataFrame(list(zip(c,d)))
print(e)

    0   1
0  序号  成本
1   1  20
2   2  45
3   3  12
4   4  34
5   5  67

#设置新列名
e.columns=[序号,成本]
#重置索引
e=e.drop(0,axis=0).reset_index()
e.drop(index,axis=1,inplace=True)
print(e)

  序号  成本
0  1  20
1  2  45
2  3  12
3  4  34
4  5  67

 

以上是关于合并多个Series为DataFrame并且重置索引的主要内容,如果未能解决你的问题,请参考以下文章