r"""Calculate the mean on a rolling basis. Parameters ---------- f : pandas.DataFrame Dataframe containing the column ``c``. c : str Name of the column in the dataframe ``f``. p : int The period over which to calculate the rolling mean. Returns -
(f, c, p = 20)
| 887 | # |
| 888 | |
| 889 | def ma(f, c, p = 20): |
| 890 | r"""Calculate the mean on a rolling basis. |
| 891 | |
| 892 | Parameters |
| 893 | ---------- |
| 894 | f : pandas.DataFrame |
| 895 | Dataframe containing the column ``c``. |
| 896 | c : str |
| 897 | Name of the column in the dataframe ``f``. |
| 898 | p : int |
| 899 | The period over which to calculate the rolling mean. |
| 900 | |
| 901 | Returns |
| 902 | ------- |
| 903 | new_column : pandas.Series (float) |
| 904 | The array containing the new feature. |
| 905 | |
| 906 | References |
| 907 | ---------- |
| 908 | *In statistics, a moving average (rolling average or running average) |
| 909 | is a calculation to analyze data points by creating series of averages |
| 910 | of different subsets of the full data set* [WIKI_MA]_. |
| 911 | |
| 912 | .. [WIKI_MA] https://en.wikipedia.org/wiki/Moving_average |
| 913 | |
| 914 | """ |
| 915 | new_column = f[c].rolling(p).mean() |
| 916 | return new_column |
| 917 | |
| 918 | |
| 919 | # |