I am not able to view nba_api data frame - python

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'

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.

Related

visualising data with python of time series and float colmn

i have the following quastion-
What can you tell about the relationship between time and speed? Is there a best time of day to connect? Has it changed throughout the years?
this is my dataframedataframe
my columns
data
does any one have any suggestion on how i would aprouch this question ?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
df = pd.read_csv('/Users/dimagoroh/Desktop/data_vis/big_file.csv', low_memory=False)
sns.lmplot(x="hours",y="speed",data=df)
im trying to do a plot but get this error i think i need to manipulate the hour column to a diffrent data type right now it is set as object
Please post the error you get. From the data I think you need to pass x="hour" and not x="hours". Also try
df.hour = pd.to_datetime(df.hour)

Can't choose a column of a data frame on Python

I'm trying to plot a figure on Python but I get a KeyError. I can't read the column "Cost per Genome" for some reason.
Here is my code:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("Sequencing_Cost_Data_Table_Aug2021 - Data Table.csv") #The data can be found here: https://docs.google.com/spreadsheets/d/1auLPEnAp0aI__zIyK9fKBAkLpwQpOFBx9qOWgJoh0xY/edit#gid=729639239
fig = plt.figure()
plt.plot(data["Date"],data["Cost per Genome"])
It looks like either you have interpreted the data wrong into the Dataframe, of made an error with the plot. Read this. It might help you further: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
P.S. I couldn't acces your spreadsheet. It was request only

PyCharm not showing dataframe when I press ctrl+alt+f10

I'm trying to backtest a simple strategy of mine and the first step is to retrieve historical data from yfinance. However, whenver I run this, I can't see the contents of hist. Instead, it just has this outputthis output
# import all the libraries
import nsetools as ns
import pandas as pd
import numpy
from datetime import datetime
import yfinance as yf
import matplotlib.pyplot as plot
plot.style.use('classic')
a = input("Enter the ticker name you wish to apply strategy to")
ticker = yf.Ticker(a)
hist = ticker.history(period="1mo", interval="5m")
hist
I really just want to see the historical prices against the time but can't get the dataframe to appear. I would appreciate any input on this.

So basically the info() command doesn't apply to tables that is directly pulled off by pandas?

Here is my code:
import pandas as pd
import numpy as np
import seaborn as sns
url = "http://www.collegesimply.com/colleges/california/"
ca_colleges = pd.read_html(url)
ca_colleges.info()
The last line gives me this error:
AttributeError: 'list' object has no attribute info().
I'd like to know where did I get it wrong?
pd.read_html returns a list of dataframes. So, you need to do it like this:
df = ca_colleges[0]
df.info()

CSV read error in Python using Panda

I want to read a csv file
import pandas as pd
import numpy as np
import matplotlib as plt
from pandas import DataFrame
df = pd.read_csv(r'C:\Andy\DataScience\python\Loan_Prediction\Train.csv')
df.head(10)
But getting error as below
IOError: File Train.csv does not exist
But the file does exist in the location.
If using backslash, because it is a special character in Python, you must remember to escape every instance
import pandas as pd
import numpy as np
import matplotlib as plt
from pandas import DataFrame
df = pd.read_csv(r'C:\\Andy\\DataScience\\python\\Loan_Prediction\\Train.csv')
df.head(10)
your read_csv could not find the path for reading the csv you have to give forward slashes
import pandas as pd
import numpy as np
import matplotlib as plt
from pandas import DataFrame
df = pd.read_csv('C:/Andy/DataScience/python/Loan_Prediction/Train.csv')
if it again gives error then just double the slashes to avoid any special character.
df = pd.read_csv('C://Andy//DataScience//python//Loan_Prediction//Train.csv')
df.head(10)

Categories

Resources