Generate a pandas dataframe from ordereddict?
Following this answer, you need to explicitly specify your column order:
df = pd.DataFrame(orderedDictList, columns=orderedDictList.keys())
Of course, first you need to ensure that you have an ordered dictionary.
You can do something like this using Counter
from collections
module:
from collections import OrderedDict, Counter
import pandas as pd
a = {'key_a': 'value_a', 'key_b':'value_b'}
b = {'key_a': 'value_c', 'key_b':'value_d'}
ord_list = [OrderedDict(a), OrderedDict(b)]
col = Counter()
for k in ord_list:
col.update(k)
df = pd.DataFrame([k.values() for k in ord_list], columns = col.keys())
print(df)
Output:
key_b key_a
0 value_b value_a
1 value_d value_c