【问题标题】:Pandas dataframe accessing and timeseriesPandas 数据帧访问和时间序列
【发布时间】:2017-06-27 01:29:38
【问题描述】:
import pandas as pd
import numpy as np
from datetime import datetime
import matplotlib.pyplot as plt

a = pd.read_excel('C:\Users\user\Desktop\INTERNSHIP\SOLAR_DADRI\data.xlsx', 
index_col='Date/ Time')
pd.to_datetime(a.index)
a['Date/ Time']

当我试图获取一个存在的列时,我遇到了一个关键错误。间距是对的。我也收到一个错误,当我简单地执行 plot(ts) 时,我无法将字符串转换为浮点数,即时间或 x 轴。 另外,当我尝试查看它说的索引类型时 pandas.indexes.base.Index

【问题讨论】:

  • 所以a['Date/ Time 按预期显示列?
  • 不显示关键错误

标签: pandas dataframe time-series


【解决方案1】:

当您使用参数index_col 时,您将该列移动到索引中。在单个索引数据框中,您可以在示例中使用“a.index”访问此列中的内容。如果您使用a.reset_index() 并将该索引移回列中,您应该能够使用a['Date/ Time'] 访问该列。

【讨论】:

  • 谢谢。所以我要明白,在单个索引数据帧中,我无法使用 a[] 输出索引列,必须执行 a.index
  • 正确,您以 a.index 的形式访问索引。
  • @Anshitsingh 如果对你有帮助,你会考虑accepting这个答案吗?
猜你喜欢
  • 2020-12-04
  • 1970-01-01
  • 1970-01-01
  • 2022-01-06
  • 1970-01-01
  • 2021-12-15
  • 2016-02-22
  • 2020-09-23
  • 2016-03-02
相关资源
最近更新 更多