Skip to content

Problem with to_dict('records') in 0.24 #25050

Closed
@Javert899

Description

@Javert899

Hi,

Running the following code in Pandas 0.24, the column names of the later object are completely wrong. May be that when the column name contains a : the to_dict('records') method is bugged?

CODE:

import pandas as pd

df = pd.read_csv("C:\running-example.csv")
print(df.columns)
print(df.to_dict().keys())
print(df.to_dict('records'))

OUTPUT:

Index(['Unnamed: 0', 'Activity', 'Costs', 'Resource', 'case:concept:name',
'case:creator', 'concept:name', 'org:resource', 'time:timestamp'],
dtype='object')
dict_keys(['Unnamed: 0', 'Activity', 'Costs', 'Resource', 'case:concept:name', 'case:creator', 'concept:name', 'org:resource', 'time:timestamp'])
[{'_0': 0, 'Activity': 'register request', 'Costs': 50, 'Resource': 'Pete', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'register request', '_7': 'Pete', '_8': '2010-12-30 14:32:00+01:00'}, {'_0': 1, 'Activity': 'examine casually', 'Costs': 400, 'Resource': 'Mike', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'examine casually', '_7': 'Mike', '_8': '2010-12-30 15:06:00+01:00'}, {'_0': 2, 'Activity': 'check ticket', 'Costs': 100, 'Resource': 'Ellen', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'check ticket', '_7': 'Ellen', '_8': '2010-12-30 16:34:00+01:00'}, {'_0': 3, 'Activity': 'decide', 'Costs': 200, 'Resource': 'Sara', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'decide', '_7': 'Sara', '_8': '2011-01-06 09:18:00+01:00'}, {'_0': 4, 'Activity': 'reinitiate request', 'Costs': 200, 'Resource': 'Sara', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'reinitiate request', '_7': 'Sara', '_8': '2011-01-06 12:18:00+01:00'}, {'_0': 5, 'Activity': 'examine thoroughly', 'Costs': 400, 'Resource': 'Sean', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'examine thoroughly', '_7': 'Sean', '_8': '2011-01-06 13:06:00+01:00'}, {'_0': 6, 'Activity': 'check ticket', 'Costs': 100, 'Resource': 'Pete', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'check ticket', '_7': 'Pete', '_8': '2011-01-08 11:43:00+01:00'}, {'_0': 7, 'Activity': 'decide', 'Costs': 200, 'Resource': 'Sara', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'decide', '_7': 'Sara', '_8': '2011-01-09 09:55:00+01:00'}, {'_0': 8, 'Activity': 'pay compensation', 'Costs': 200, 'Resource': 'Ellen', '_4': 3, '_5': 'Fluxicon Nitro', '_6': 'pay compensation', '_7': 'Ellen', '_8': '2011-01-15 10:45:00+01:00'}, {'_0': 9, 'Activity': 'register request', 'Costs': 50, 'Resource': 'Mike', '_4': 2, '_5': 'Fluxicon Nitro', '_6': 'register request', '_7': 'Mike', '_8': '2010-12-30 11:32:00+01:00'}, {'_0': 10, 'Activity': 'check ticket', 'Costs': 100, 'Resource': 'Mike', '_4': 2, '_5': 'Fluxicon Nitro', '_6': 'check ticket', '_7': 'Mike', '_8': '2010-12-30 12:12:00+01:00'}, {'_0': 11, 'Activity': 'examine casually', 'Costs': 400, 'Resource': 'Sean', '_4': 2, '_5': 'Fluxicon Nitro', '_6': 'examine casually', '_7': 'Sean', '_8': '2010-12-30 14:16:00+
................

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions