Pandas 1.1.4
Consider
df4 = pd.DataFrame({
'a': [1, 2, 3, 4]
})
counts = df4.value_counts().astype(np.int)
print(counts.index)
counts.reindex(counts.index.to_flat_index())
print(counts.index)
print(counts.index.to_flat_index())
output:
MultiIndex([(4,), (3,), (2,), (1,)], names=['a']) MultiIndex([(4,), (3,), (2,), (1,)], names=['a']) Index([(4,), (3,), (2,), (1,)], dtype='object')
I want to be able to interchange with
df5 = pd.Series([5, 6, 7, 8], index=[1, 2, 3, 4])
print(df5.index)
whose index is
Int64Index([1, 2, 3, 4], dtype='int64').
Please notice df4's index is the same as df5's, but the value_counts makes it into a multi index.
How to I work around this? No flatten I try seems to work.