Tengo una lista de listas y quiero convertirla en DataFrames. Por ejemplo aqui esta una lista :
[[{'count': 6L, 'eclipse_id': 11348}, {'count': 1L, 'eclipse_id': 11338},
{'count': 1L, 'eclipse_id': 11342}, {'count': 1L, 'eclipse_id': 11361},
{'count': 6L, 'eclipse_id': 11313}],
[[{'count': 1L, 'eclipse_id': 11374},{'count': 1L, 'eclipse_id': 11356},
{'count': 1L, 'eclipse_id': 11358}]]
El resultado esperado
Sería varios arrays según la lista dentro de la lista:
Primera matriz:
count eclipse_id
0 6 11348.0
1 1 11338.0
2 1 11342.0
3 1 11361.0
4 6 11313.0
Segunda matriz:
count eclipse_id
0 1 11374.0
1 1 11356.0
2 1 11358.0
Sería aún más maravilloso si se ordenó!
Mi intento
Esto es lo que intenté:
i = 0
for liste in listeGroupContentReactions:
df_n[i] = pd.DataFrame(liste)
i+1
Sin emargo me respuesta ValueError: Wrong number of items passed 2, placement implies 1
El error completo es el siguiente:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-64-851a5559a58d> in <module>()
6 i = 0
7 for liste in listeGroupContentReactions:
----> 8 df_n[i] = pd.DataFrame(liste)
9 i+1
10
/home/antoine/anaconda2/lib/python2.7/site-packages/pandas/core/frame.pyc in __setitem__(self, key, value)
2427 else:
2428 # set column
-> 2429 self._set_item(key, value)
2430
2431 def _setitem_slice(self, key, value):
/home/antoine/anaconda2/lib/python2.7/site-packages/pandas/core/frame.pyc in _set_item(self, key, value)
2494 self._ensure_valid_index(value)
2495 value = self._sanitize_column(key, value)
-> 2496 NDFrame._set_item(self, key, value)
2497
2498 # check if we are modifying a copy
/home/antoine/anaconda2/lib/python2.7/site-packages/pandas/core/generic.pyc in _set_item(self, key, value)
1646
1647 def _set_item(self, key, value):
-> 1648 self._data.set(key, value)
1649 self._clear_item_cache()
1650
/home/antoine/anaconda2/lib/python2.7/site-packages/pandas/core/internals.pyc in set(self, item, value, check)
3716 except KeyError:
3717 # This item wasn't present, just insert at end
-> 3718 self.insert(len(self.items), item, value)
3719 return
3720
/home/antoine/anaconda2/lib/python2.7/site-packages/pandas/core/internals.pyc in insert(self, loc, item, value, allow_duplicates)
3817
3818 block = make_block(values=value, ndim=self.ndim,
-> 3819 placement=slice(loc, loc + 1))
3820
3821 for blkno, count in _fast_count_smallints(self._blknos[loc:]):
/home/antoine/anaconda2/lib/python2.7/site-packages/pandas/core/internals.pyc in make_block(values, placement, klass, ndim, dtype, fastpath)
2717 placement=placement, dtype=dtype)
2718
-> 2719 return klass(values, ndim=ndim, fastpath=fastpath, placement=placement)
2720
2721 # TODO: flexible with index=None and/or items=None
/home/antoine/anaconda2/lib/python2.7/site-packages/pandas/core/internals.pyc in __init__(self, values, placement, ndim, fastpath)
113 raise ValueError('Wrong number of items passed %d, placement '
114 'implies %d' % (len(self.values),
--> 115 len(self.mgr_locs)))
116
117 @property
ValueError: Wrong number of items passed 2, placement implies 1