python - Prevent Pandas from unpacking a tuple when creating a dataframe from dict -
when creating dataframe in pandas dictionary, tuple automatically expanded, i.e.
import pandas d = {'a': 1, 'b': 2, 'c': (3,4)} df = pandas.dataframe.from_dict(d) print(df)
returns
b c 0 1 2 3 1 1 2 4
apart converting tuple string first, there way prevent happening? want result be
b c 0 1 2 (3, 4)
try add []
, value in dictionary
key c
list
of tuple
:
import pandas d = {'a': 1, 'b': 2, 'c': [(3,4)]} df = pandas.dataframe.from_dict(d) print(df) b c 0 1 2 (3, 4)
Comments
Post a Comment