Pandas設置DataFrame的index索引起始值為1的兩種方法
更新時間:2024年07月23日 10:57:01 作者:山茶花開時。
DataFrame中的index索引列默認是從0開始的,那么我們?nèi)绾卧O置index索引列起始值從1開始呢,本文主要介紹了Pandas設置DataFrame的index索引起始值為1的兩種方法,感興趣的可以了解一下
導入數(shù)據(jù)
import pandas as pd df = pd.DataFrame([['liver','E',89,21,24,64], ['Arry','C',36,37,37,57], ['Ack','A',57,60,18,84], ['Eorge','C',93,96,71,78], ['Oah','D',65,49,61,86] ], columns = ['name','team','Q1','Q2','Q3','Q4'])
df
上述DataFrame中的index索引列默認是從0開始的,那么我們?nèi)绾卧O置index索引列起始值從1開始呢?
方法1
df.index = df.index + 1
方法2
df.index = range(1,len(df)+1)
df
到此這篇關于Pandas設置DataFrame的index索引起始值為1的兩種方法的文章就介紹到這了,更多相關Pandas索引起始值為1內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!