pandas cumsum
时间: 2023-09-26 20:04:35 浏览: 80
pandas cumsum() is a function used to calculate the cumulative sum of a given data frame or series. It returns a new data frame or series where each element is the sum of all the previous elements in the data frame or series. The cumsum() function is applied on a one-dimensional data frame or series.
Syntax:
pandas.Series.cumsum(axis=None, skipna=True, *args, **kwargs)
Parameters:
axis: It is used to specify the axis along which the function needs to be applied. By default, it is None.
skipna: It is used to specify whether to exclude NaN values while performing the cumsum operation. By default, it is True.
Returns:
The cumsum() function returns a new data frame or series containing the cumulative sum of the input data frame or series.
Example:
import pandas as pd
data = [10, 20, 30, 40, 50]
df = pd.Series(data)
cumulative_sum = df.cumsum()
print(cumulative_sum)
Output:
0 10
1 30
2 60
3 100
4 150
dtype: int64
阅读全文