Python Pandas dataframe.cumprod()用法及代码示例 | 您所在的位置:网站首页 › python累乘函数怎么写 › Python Pandas dataframe.cumprod()用法及代码示例 |
Python是进行数据分析的一种出色语言,主要是因为以数据为中心的python软件包具有奇妙的生态系统。 Pandas是其中的一种,使导入和分析数据更加容易。 Pandas dataframe.cumprod()用于查找到目前为止在任何轴上看到的值的累积乘积。每个单元格都填充了到目前为止看到的值的累积乘积。 用法: DataFrame.cumprod(axis=None, skipna=True, *args, **kwargs)参数: axis:{索引(0),列(1)} skipna:排除NA /空值。如果整个行/列均为NA,则结果为NA 返回:cumprod:系列 范例1:采用cumprod()函数可以找到到目前为止沿索引轴看到的值的累积乘积。 # importing pandas as pd import pandas as pd # Creating the dataframe df = pd.DataFrame({"A":[5, 3, 6, 4], "B":[11, 2, 4, 3], "C":[4, 3, 8, 5], "D":[5, 4, 2, 8]}) # Print the dataframe df输出: 现在找到到目前为止在索引轴上看到的值的累积乘积 # To find the cumulative prod df.cumprod(axis = 0)输出:
范例2:采用cumprod()函数可查找到目前为止沿列轴看到的值的累积乘积。 # importing pandas as pd import pandas as pd # Creating the dataframe df = pd.DataFrame({"A":[5, 3, 6, 4], "B":[11, 2, 4, 3], "C":[4, 3, 8, 5], "D":[5, 4, 2, 8]}) # cumulative product along column axis df.cumprod(axis = 1)输出: 范例3:采用cumprod()函数查找迄今在 DataFrame 中沿索引轴看到的值的累积乘积NaN DataFrame 中存在的值。 # importing pandas as pd import pandas as pd # Creating the dataframe df = pd.DataFrame({"A":[5, 3, None, 4], "B":[None, 2, 4, 3], "C":[4, 3, 8, 5], "D":[5, 4, 2, None]}) # To find the cumulative product df.cumprod(axis = 0, skipna = True)输出:
输出是一个 DataFrame ,其中的单元格包含沿索引轴迄今看到的值的累积乘积。任何Nan DataFrame 中的值将被跳过。
|
CopyRight 2018-2019 实验室设备网 版权所有 |