我正在采取一个数据框,将其分成两个数据框,然后我需要更改索引值,以便没有数字大于总行数。有更简单的方法来改变熊猫数据框的索引值吗?
下面的代码:
dataset = pd.read_csv("dataset.csv",usecols['row_id','x','y','time'],index_col=0)
splitvalue = math.floor((0.9)*786239)
train = dataset[dataset.time < splitvalue]
test = dataset[dataset.time >= splitvalue]
下面是我做的改变。我想知道是否有更简单的方法:
test.index=range(test.shape[0])
test.index.rename('row_id',inplace=True)
有没有更好的方法来做到这一点?
感谢您的建议。我没有意识到可以通过重新索引来完成洗牌。凉。 –
@LarryFreeman,不要检查与新的数据框头..头排序索引,然后显示......驱使我坚持一会儿。 – Merlin
如果我不检查head(),有什么替代方法? –