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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -