0

I have the following data:

data = [
    (132603, 'TV Series', 'hbo', 'Chris Rock', datetime.date(2008, 9, 2), datetime.datetime(2019, 2, 6, 2, 16)), 
    (132605, 'TV Series', 'madman', 'Joanna Lumley', datetime.date(2012, 10, 24), datetime.datetime(2019, 2, 5, 16, 45))
]

And I create a dataframe as follows:

>>> pd.DataFrame(data)

        0          1       2              3           4                   5
0  132603  TV Series     hbo     Chris Rock  2008-09-02 2019-02-06 02:16:00
1  132605  TV Series  madman  Joanna Lumley  2012-10-24 2019-02-05 16:45:00

How would I specify a headers column when creating the dataframe, such as:

pd.DataFrame(data, headers=['id', 'type','network','start','end'])
  • `pd.DataFrame(data, columns=['id', 'type','network','missing_column','start','end'])` your list of headers has 5 entries whereas your data has 6 headers. fix that and use this syntax – anky Feb 09 '19 at 03:10
  • Try to at least glance at the [documentation](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html) before posting a question. – rafaelc Feb 09 '19 at 03:12

1 Answers1

1

If you check the fine manual page, you'll find that columns= does what you want.

aghast
  • 14,785
  • 3
  • 24
  • 56