Why is df.head() not working in python

15,137

You need to change the list to a pandas DataFrame first. After that you will be able to do data.head(). Something like:

df = pd.DataFrame(my_list)
Share:
15,137

Related videos on Youtube

Akhil
Author by

Akhil

Updated on June 04, 2022

Comments

  • Akhil
    Akhil almost 2 years

    Hi there everyone I am working on a project with python which needs data frames so I am using pandas but there seem to be a problem to when ever I go and type in print(data.head()) AttributeError: 'list' object has no attribute 'head' below is the rest of my code any help will be awesome.

    import quandl
    import pandas as pd
    import numpy as np
    
    data = quandl.get_table('WIKI/PRICES')
    print(data.head())
    
    • Zero
      Zero over 6 years
      What is type(data)? probably not a dataframe, looks like a list. print data and check for contents.
    • Andrey Lukyanenko
      Andrey Lukyanenko over 6 years
      I suppose that you need to convert data into df: data = pd.DataFrame(data)