[英]Dataframe : How do I perform the below calculation in one of my columns?
您可以使用以下代碼:
import pandas as pd
# initialize list of lists
data = [['0', 75], ['1', 10], ['2', 94], ['3', 96]]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns = ['index', 'value'])
df["avrage"]=df['value'].expanding().mean()
# print dataframe.
df
index value avrage
0 0 75 75.000000
1 1 10 42.500000
2 2 94 59.666667
3 3 96 68.750000
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.