0

I am trying to understand rolling function on pandas on python here is my example code

# 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 input file has 255 entries but I get few entries on the output, I get "..." between 2018-10-04 and 2017-12-26. I verified the input file, it has a lot more valid entries in between these dates.

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

thank you for your help ...

prakash
  • 3
  • 2

1 Answers1

1

... just means that pandas isn't showing you all the rows, that's where the 'missing' ones are.

To display all rows:

with pd.option_context("display.max_rows", None):
    print (df.close.rolling(3, win_type ='triang').sum())
ignoring_gravity
  • 6,677
  • 4
  • 32
  • 65