数据框set_index未设置 [英] Dataframe set_index not setting

查看:67
本文介绍了数据框set_index未设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据框,正在尝试将索引设置为时间戳"列.当前索引只是一个行号.时间戳格式的示例是: 2015-09-03 16:35:00

I have a dataframe and am trying to set the index to the column 'Timestamp'. Currently the index is just a row number. An example of Timestamp's format is: 2015-09-03 16:35:00

我尝试设置索引:

df.set_index('Timestamp')

我没有收到错误,但是当我打印数据框时,索引仍然是行号.如何使用时间戳记作为索引?

I don't get an error, but when I print the dataframe, the index is still the row number. How can I use Timestamp as the index?

推荐答案

您需要指定inplace=True,或将结果分配给变量.试试:

You need to either specify inplace=True, or assign the result to a variable. Try:

df.set_index('Timestamp', inplace=True, drop=True)

这篇关于数据框set_index未设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆