Skip to content
Advertisement

Converting a iterable of ordered dict’s to pandas dataframe

I am iterating over OrderedDict’s and want to store them as pandas dataframe. Is there a commend to do that? Currently, the code is:

One row in res looks like this:

OrderedDict([('field_id', 1), ('date', datetime.date(2016, 1, 3)), ('temp', 30.08), ('norm_temperature', None), ('prcp', 12.8848107785339), ('abcd', 0.0), ('efgh', None), ('ijkl', 1.38), ('lmno', None), ('poq', None)])

df = pd.DataFrame(res)

I get this error: *** TypeError: data argument can't be an iterator

How do I store this iterator over ordered dict’s into a dataframe?

Advertisement

Answer

If res is like this:

res = iter([row1,row2,...])

You can do it this way:

df = pd.DataFrame(*[res])
Advertisement