import pandas as pd df = pd.DataFrame({"col1": list(range(10)), "col2": list(range(1, 11)), "col3": "2" * 10}) print(df.shape) print(df) # 找出df中每列的最小值、最大值,生成新DataFrame print(df.agg(['min','max'])) # 对df中的数字列,每三行(本行及前两行)求和 print(df.rolling(3, min_periods=1).sum(numeric_only=True)) # 对df中的数字列,每四行求平均值 print(df.rolling(4, min_periods=1).mean(numeric_only=True)) # 对df中的所有列,每五行计数,小于两行的不计入 print(df.rolling(5, min_periods=2).count()) # 给df增加日期时间索引 df = pd.DataFrame({"col1": list(range(10)), "col2": list(range(1, 11)), "col3": "2" * 10}, index=pd.date_range("2020-1-1", "2020-1-10")) # 按时间频率在df中生成新的行 print(df.asfreq("0.5D"))
参考:https://www.cnblogs.com/traditional/p/13776180.html
https://www.gairuo.com/p/pandas-agg
标签:10,min,agg,print,df,range,rolling,asfreq From: https://www.cnblogs.com/pu369/p/17353533.html