The following python code is giving me an AssertionError:
p = DataFrame.groupby(column).apply(len).sort_values(ascending=False)
q = DataFrame[column].value_counts()
pd.testing.assert_series_equal(p, q)
I thought these functions do the same thing and in fact the resulting series are similar when looking at the first few rows but according to the assertion error they are only 59% similar.
Both are almost similar, only need same index names and same Series names - set all to default None:
DataFrame = pd.DataFrame({'a': [1,5,4,2,1,2,1,2,1,4,2,3,2,1]})
column = 'a'
p = DataFrame.groupby(column).apply(len).sort_values(ascending=False)
q = DataFrame[column].value_counts()
print (p.name)
None
print (q.name)
a
print (p.index.name)
a
print (q.index.name)
None
pd.testing.assert_series_equal(p.rename_axis(None), q.rename(None))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With