pandas - 如何从数据框中删除库存日期列
问题描述
运行下面链接中的代码会得到以下输出
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
解决方案
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'])
推荐阅读
- python - K.random_normal(shape=(batch, dim)) 的 Tflite TOCO 转换失败
- reactjs - Apollo - 构建生产构建时的 React (Typescript) 不变错误
- python - 如何使 `fit_generator` 与 `tf.keras.Model` 一起工作
- c# - ASP.net 防止 gridview 行在编辑模式下单击
- anylogic - 使用从主要代理到不同代理的代理参数?
- c# - C# 从 MySQL 更新 DataGridView/DataSource
- c# - 如何将列表值保存到 C# 中的各个列
- javascript - 似乎无法在不破坏父级的情况下关闭此模式?
- ios - 如何在 iPhone 上滚动到 UITableView 的底部而不看到滚动
- html - 填充在滚动 div 中重复,在边缘工作,但在 chrome 中不工作