[Python] Python Pandas - how to read in data from list (data) and columns (separate list)

Discussão em 'Python' iniciado por Stack, Janeiro 29, 2025.

  1. Stack

    Stack Membro Participativo

    I'm a newbie and running into a situation I don't know what to do:

    The data is a list, no index. Sample data: [{'fields': ['2024-10-07T21:22:01', 'USER-A', 21, 0, 0, 21]}, {'fields': ['2024-10-07T21:18:28', 'USER-B', 20, 20, 0, 0, 0, 45]}

    The column header is in another: ['Created On', 'Created By', 'Transaction Count (ALL)', 'X Pending', 'X Cancelled (X)', 'X Completed (Y)']

    I have tried using pandas.DataFrame as well as json_normalize, I either get a single column table with each value as a row, or I got all values as a column, and when I try with using "fields", it tells me "list indices must be integers or slices, not str" which I don't understand why I get this... what is the best way to have these info into a dataframe please?

    (the number of data elements and number of column headers may not be consistent just for example sake, the real data has things aligned)

    Thanks for your help!

    Continue reading...

Compartilhe esta Página