首页 > 解决方案 > 如何从数据框中删除库存日期列

问题描述

运行下面链接中的代码会得到以下输出

Index(['High', 'Low', 'Open', 'Close', 'Volume', 'Adj Close'], dtype='object')

代码抓取在数据框中像这样显示的雅虎股票价格

    High    Low Open    Close   Volume  Adj Close
Date                        
2014-04-03  10.800  9.05    9.86    9.06    12004000.0  8.681220
2014-04-04  9.380   8.73    9.10    9.04    1844100.0   8.662056
2014-04-07  8.950   7.99    8.86    8.06    2562600.0   7.723028
2014-04-08  8.604   8.06    8.12    8.50    959500.0    8.144632
2014-04-09  8.660   8.20    8.47    8.44    981000.0    8.087140

如何删除日期列,以便我的训练数据包含显示为 dtype='object' 的数据

https://colab.research.google.com/drive/1uEHKCntVS73b9WQvTxwTegpnbBtI4VNK?usp=sharing

标签: pandas

解决方案


Date是这里的索引,所以你有两个选择;

1.直接删除索引;

df.reset_index(drop=True, inplace=True)

2.使用按类型选择列.select_dtypes()

# 'Date' to column 
df = df.reset_index()

# select strings too
df = df.select_dtypes(include=['object'])

推荐阅读