Closed
Description
Currently, passing a list of namedtuple
s (or SQLAlchemy results, which is our specific case) to DataFrame.from_records
doesn't resolve the field names.
I think it would make sense to, at least if the names are all the same. Happy to do a PR if people agree.
In [17]: from collections import namedtuple
In [18]: Record = namedtuple('Record',('date','value'))
In [19]: records = [Record(d, v) for (d, v) in zip(pd.date_range('2000',freq='D', periods=20), range(20))]
In [20]: records
Out[20]:
[Record(date=Timestamp('2000-01-01 00:00:00', offset='D'), value=0),
Record(date=Timestamp('2000-01-02 00:00:00', offset='D'), value=1),
...
Record(date=Timestamp('2000-01-19 00:00:00', offset='D'), value=18),
Record(date=Timestamp('2000-01-20 00:00:00', offset='D'), value=19)]
In [21]: pd.DataFrame.from_records(records)
Out[21]:
0 1
0 2000-01-01 0
1 2000-01-02 1
...
18 2000-01-19 18
19 2000-01-20 19
Desired behavior:
Out[21]:
date value
0 2000-01-01 0
1 2000-01-02 1
...
18 2000-01-19 18
19 2000-01-20 19