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

时间:2020-06-26 17:56:23   收藏:0   阅读:217
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

 

原文:https://www.cnblogs.com/luckiness/p/13195480.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!