在执行以下代码时,我得到了以下错误:
import pandas as pd
reviews=pd.read_csv("/kaggle/input/fivethirtyeight-fandango-dataset/fandango_score_comparison.csv")
print(reviews.head())
cols=['FILM','RT_user_norm','Metacritic_User','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
norm_reviews=reviews[cols]
#print(norm_reviews)
print(norm_reviews[0:1])
import matplotlib. pyplot as plt
from numpy import arange
num_cols=['FILM','RT_user_norm','Metacritic_User','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars']
bar_heights=norm_reviews.loc[0,num_cols].values
print(help(bar_heights))
print(bar_heights)
bar_positions=arange(5)+0.75
fig, ax= plt.subplots()
ax.bar(bar_positions,bar_heights,0.3)
plt.show()下面是错误:
/opt/conda/lib/python3.7/site-packages/matplotlib/category.py in __init__(self, data)
179 self._counter = itertools.count()
180 if data is not None:
--> 181 self.update(data)
182
183 @staticmethod
/opt/conda/lib/python3.7/site-packages/matplotlib/category.py in update(self, data)
217 # OrderedDict just iterates over unique values in data.
218 if not isinstance(val, (str, bytes)):
--> 219 raise TypeError("{val!r} is not a string".format(val=val))
220 if convertible:
221 # this will only be called so long as convertible is True.
TypeError: 4.3 is not a string在行bar_heights=norm_reviews.loc[0,num_cols].values之前是bar_heights=norm_reviews.ix[0,num_cols].values,这又给出了另一个错误。将$ix$更改为$loc$后,出现字符串错误
发布于 2020-05-09 03:15:27
我确信有一种更好的方法来格式化它,但这在FWIW中有效。
import pandas as pd
import matplotlib. pyplot as plt
from numpy import arange
plt.style.use('seaborn')
review = pd.read_csv("https://raw.githubusercontent.com/fivethirtyeight/data/master/fandango/fandango_score_comparison.csv")
review_filtered = review.filter(['FILM','RT_user_norm','Metacritic_User','IMDB_norm','Fandango_Ratingvalue','Fandango_Stars'])
col_names = ['Movie', 'RT User', 'Metacritic User', 'IMDB Score', 'Fandango Rating', 'Fandango Stars']
review_filtered.plot(kind = 'bar', xticks= [], width = 0.3, legend='upper right')
plt.show
https://stackoverflow.com/questions/61665751
复制相似问题