I'm calculating a coskew matrix and wanted to double check my calculation with pandas built in skew
method. I could not reconcile how pandas performing the calculation.
define my series as:
import pandas as pd
series = pd.Series(
{0: -0.051917457635120283,
1: -0.070071606515280632,
2: -0.11204865874074735,
3: -0.14679988245503134,
4: -0.088062467095565145,
5: 0.17579741198527793,
6: -0.10765856028420773,
7: -0.11971470229167547,
8: -0.15169210769159247,
9: -0.038616800990881606,
10: 0.16988162977411481,
11: 0.092999418364443032}
)
I compared the following calculations and expected them to be the same.
pandas
series.skew()
1.1119637586658944
me
(((series - series.mean()) / series.std(ddof=0)) ** 3).mean()
0.967840223081231
me - take 2
This is significantly different. I thought it might be Fisher-Pearson coefficient. So I did:
n = len(series)
skew = series.sub(series.mean()).div(series.std(ddof=0)).apply(lambda x: x ** 3).mean()
skew * (n * (n - 1)) ** 0.5 / (n - 1)
1.0108761442417222
Still off by quite a bit.
Question
How does pandas calculate skew?