So I am attempting to plot the number of Shark Attacks by country from a supplied Dataset in the form of a CSV file. I am relatively new to Python and the Pandas and Matplotlib libraries and am having difficulty with syntax I believe.
Currently I'm running into an error:
AttributeError: 'NoneType' object has no attribute 'update'
Here is my Code:
import pandas as pd
import matplotlib.pyplot as plt; plt.rcdefaults()
import numpy as np
import matplotlib.pyplot as plt
#read in csv file
df = pd.read_csv('SharkAttack.csv',delimiter=",", encoding='cp1252', header=0)
#Correct Missing Country Names
df.loc[df['Area'].str.contains('Florida', na=False), 'Country'] = 'USA'
#correct Missing Values
df.fillna("NaN")
x = df['Country'].unique().tolist()
y = df['Country'].nunique()
plt.bar(x, y, align='center', alpha=0.5)
plt.ylabel('Number Of Attacks')
plt.xlabel("Country")
plt.title('Shark Attacks by Country')
plt.show()
Any idea how I can fix this? IT was simple enough to create an array when the number of unique items in the list was small enough to hard code, but there is a massive list of countries in the file.