Creating series with multiindex from dict with tuple keys with None · Issue #18505 · pandas-dev/pandas (original) (raw)
Code Sample
import pandas as pd
data1={(1, 2): 3, (4, None): 6}
s1 = pd.Series(data=data1)
data2={(1, 2): 3, (None, 5): 6}
s2 = pd.Series(data=data2)
Problem description
s1
has MultiIndex while s2
has Index of tuple just because the second element of the data2
has None
as the first element of the key tuple.
s1 1 2 3.0 4 NaN NaN dtype: float64 s2 (1, 2) 3 (None, 5) 6 dtype: int64
Is this a bug? or is this how it's supposed to be?
FYI, both of mi1
and mi2
below yield MultiIndex as I expect.
mi1 = pd.MultiIndex.from_tuples([(1, 2), (4, None)]) mi2 = pd.MultiIndex.from_tuples([(1, 2), (None, 5)])