-1

Not sure how to resolve this error

import pandas as pd 
import numpy as np 
import seaborn as sns
import matplotlib.pyplot as plt 
import nba_api




from nba_api.stats.endpoints import leagueleaders
stats = leagueleaders.LeagueLeaders(season='2017-18')
df17 = stats.get_data_frames() 
df17.head()
'list' object has no attribute 'head'
Random Davis
  • 6,662
  • 4
  • 14
  • 24
  • 1
    So, `get_data_frames` is returning a `list`, and its name indicates that this is a `list` of `dataframe`s. So, have you tried iterating through it and viewing the `head()` of each `dataframe`? Did you even look to see what was actually in the list before posting here? – Random Davis Aug 31 '22 at 18:03

2 Answers2

0

Based on the error, it looks like the API you're using is giving you the data in the form of a standard list object, not as a pandas data frame. You'll need to wrap the data inside the list obtained from the API inside a pandas data frame.

Charlie
  • 33
  • 1
  • 9
0
import pandas as pd
from nba_api.stats.endpoints import leagueleaders
stats = leagueleaders.LeagueLeaders(season='2017-18')
df17 = stats.get_data_frames()[0] 
df17.head()

The above code I have provided will work. My understanding is that get_data_frames() will always output a list of DataFrames so to separate you need to use an index.

ACE
  • 25
  • 5