pandas serIEs/DataFrame 更换索引
a = [{"content": "1", "Title": "刘德华", "info": "", "time": 1578877014}, {"content": "2", "time": 1579877014}, {"content": "3", "time": 1582877014}, {"content": "aa", "Title": "苹果", "time": 1582876014}, {"content": "15", "Title": "apple", "time": 1581877014}, {"content": "16", "Title": "banana", "time": 1561877014}, ] data = [{"content": "1", ]index=[i['content'] for i in a]s=pd.SerIEs(data,index)re_index=[eval(i['content']) for i in a]# 替换索引s.index=re_indexprint(s.index)>>> Int64Index([0, 1, 2, 3, 4, 5], dtype='int64')df.index=List(range(6))print(df.index)>>> Int64Index([0, dtype='int64')
参考文档:
pandas series/DataFrame 更换索引
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.reindex.html
总结以上是内存溢出为你收集整理的pandas series/DataFrame 更换索引全部内容,希望文章能够帮你解决pandas series/DataFrame 更换索引所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)