python-3.x - cumalativive 所有其他列都需要 python ML 中带有 cumsum() 的日期列

标签 python-3.x pandas machine-learning tensorflow2.0

我有股票数据集,例如

     **Date        Open        High  ...       Close   Adj Close    Volume**
0 2014-09-17  465.864014  468.174011  ...  457.334015  457.334015  21056800
1 2014-09-18  456.859985  456.859985  ...  424.440002  424.440002  34483200
2 2014-09-19  424.102997  427.834991  ...  394.795990  394.795990  37919700
3 2014-09-20  394.673004  423.295990  ...  408.903992  408.903992  36863600
4 2014-09-21  408.084991  412.425995  ...  398.821014  398.821014  26580100

我需要对 Open,High,Close,Adj Close, Volume 列进行累计求和

我尝试了这个 df.cumsum() ,它显示了错误时间戳错误。

最佳答案

我认为处理贸易数据最好创建DatetimeIndex:

#if necessary
#df['Date'] = pd.to_datetime(df['Date'])
df = df.set_index('Date')

然后,如果需要,所有列的累积总和:

df = df.cumsum()

如果只想对某些列进行累积和:

cols = ['Open','High','Close','Adj Close','Volume']
df[cols] = df.cumsum()

关于python-3.x - cumalativive 所有其他列都需要 python ML 中带有 cumsum() 的日期列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59316929/

相关文章:

Python在postgresql表中查找带有单引号的字符串

python - "TypeError: Input ' global_step ' of ' ResourceApplyAdagradDA ' Op has type int32 that does not match expected type of int64."这是什么错误?

python - 对象类型没有名为 length 的轴,尝试根据数据帧的长度进行排序并将其屏蔽到第二个数据帧

python - Pandas CParseError,通过 FTP 下载的文件

python - 特征选择时出错

python - 将 post.get ('href' ) 转换为文本或字符串形式,Excel 无法处理超过 255 个字符的超链接

python - 线程错误 : AttributeError: 'NoneType' object has no attribute '_initialized'

python - 迭代 excel-sheets 名称从 "Line"开始

python - 如何应用独特的函数并转换并保留数据框 pandas 中的完整列

python - 实现接口(interface)的类集合的重写方法