pandas 如何从数据框中删除库存日期列

vuktfyat  于 2022-11-20  发布在  其他
关注(0)|答案(1)|浏览(124)

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

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

o8x7eapl

o8x7eapl1#

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'])

相关问题