python - 滚动功能不会打印所有值
问题描述
我想了解 python 上 pandas 的滚动功能这是我的示例代码
# importing pandas as pd
import pandas as pd
# By default the "date" column was in string format,
# we need to convert it into date-time format
# parse_dates =["date"], converts the "date" column to date-time format
# Resampling works with time-series data only
# so convert "date" column to index
# index_col ="date", makes "date" column
df = pd.read_csv("apple.csv", parse_dates = ["date"], index_col = "date")
print (df.close.rolling(3).sum())
print (df.close.rolling(3, win_type ='triang').sum())
cvs 输入文件有 255 个条目,但输出中的条目很少,我在 2018 年 10 月 4 日和 2017 年 12 月 26 日之间得到“...”。我验证了输入文件,在这些日期之间有更多有效条目。
date
2018-11-14 NaN
2018-11-13 NaN
2018-11-12 578.63
2018-11-09 590.87
2018-11-08 607.13
2018-11-07 622.91
2018-11-06 622.21
2018-11-05 615.31
2018-11-02 612.84
2018-11-01 631.29
2018-10-31 648.56
2018-10-30 654.38
2018-10-29 644.40
2018-10-26 641.84
2018-10-25 648.34
2018-10-24 651.19
2018-10-23 657.62
2018-10-22 658.47
2018-10-19 662.69
2018-10-18 655.98
2018-10-17 656.52
2018-10-16 659.36
2018-10-15 660.70
2018-10-12 661.62
2018-10-11 653.92
2018-10-10 652.92
2018-10-09 657.68
2018-10-08 667.00
2018-10-05 674.93
2018-10-04 676.05
...
2017-12-26 512.25
2017-12-22 516.18
2017-12-21 520.59
2017-12-20 524.37
2017-12-19 523.90
2017-12-18 525.31
2017-12-15 524.93
2017-12-14 522.61
2017-12-13 518.46
2017-12-12 516.19
2017-12-11 516.64
2017-12-08 513.74
2017-12-07 511.36
2017-12-06 507.70
2017-12-05 507.97
2017-12-04 508.45
2017-12-01 510.49
2017-11-30 512.70
2017-11-29 512.38
2017-11-28 514.40
2017-11-27 516.64
2017-11-24 522.13
2017-11-22 524.02
2017-11-21 523.07
2017-11-20 518.08
2017-11-17 513.27
2017-11-16 511.23
2017-11-15 510.33
2017-11-14 511.52
2017-11-13 514.39
Name: close, Length: 254, dtype: float64
谢谢您的帮助 ...
解决方案
...
只是意味着pandas
没有向您显示所有行,这就是“缺失”行的所在。
要显示所有行:
with pd.option_context("display.max_rows", None):
print (df.close.rolling(3, win_type ='triang').sum())
推荐阅读
- java - 为什么 imageCapture.takePicture 永远不会进入 ImageCapture.OnImageSavedCallback() 的 onImageSaved()?
- javascript - 如何在 React Native 中保存 FlatList 中的项目?
- arrays - 来自字符串文本的暗淡变量
- json - vs-code "JSON: Max Item Computed" 设置实际上是做什么的?
- javascript - JS循环基于数组中的数据数量
- amazon-web-services - 如何将仪表板正文中的 ARN 替换为不包含 accountId 的内容?
- grafana - 如何创建基于其他变量的反应性 Grafana 变量,所有这些变量都在仪表板设置中定义?
- sass - WebStorm 中未解析的函数 sass math.div()
- neural-network - 如何在实践中使用图卷积网络模型(节点分类)?
- c# - 注册的自定义协议在浏览器中未被识别为链接