Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas rolling mean

#find rolling mean of previous 5 sales periods
df['rolling_sales_5'] = df['sales'].rolling(5).mean()

#view first 10 rows
df.head(10)

	period	    leads	    sales	rolling_sales_5
0	1	11.427457	61.417425	NaN
1	2	14.588598	64.900826	NaN
2	3	12.452504	66.698494	NaN
3	4	11.352780	64.927513	NaN
4	5	9.049441	73.720630	66.332978
5	6	13.271988	77.687668	69.587026
6	7	9.314157	78.125728	72.232007
7	8	17.943687	75.280301	73.948368
8	9	19.309592	73.181613	75.599188
9	10	8.285389	85.272259	77.909514
Comment

pandas rolling mean exlude current

ddf.groupby("x").rolling("1h", closed= "left")["y"].sum()
Comment

PREVIOUS NEXT
Code Example
Python :: know the type of variable in python 
Python :: namedtuple python 
Python :: remove all elements from list python by value 
Python :: comment lister les fichiers un dossier avec python 
Python :: drop 0 in np array 
Python :: invert binary tree with python 
Python :: NumPy unique Example Get unique values from a 1D Numpy array 
Python :: how to loop through pages of pdf using python 
Python :: python - join two columns and transform it as index 
Python :: python remove one character from a string 
Python :: array creation method in numpy 
Python :: pickling python example 
Python :: python call function in class 
Python :: with open 
Python :: date time shit pandas 
Python :: Link In Django 
Python :: while loops python 
Python :: BaseSSHTunnelForwarderError: Could not establish session to SSH gateway 
Python :: 231a codeforces solution in python 
Python :: how to add a linebreak in python 
Python :: manage python environment in jupyterlab 
Python :: tkinter frames and grids 
Python :: update all pip packages 
Python :: palindrome checker python 
Python :: argparse print help if no arguments 
Python :: Difference between two dates and times in python 
Python :: Javascript rendering html 
Python :: python how to drop columns from dataframe 
Python :: get first element of tuple python 
Python :: getting multiple of 5 python 
ADD CONTENT
Topic
Content
Source link
Name
5+7 =