Question: import pandas as pd import matplotlib.pyplot as plt import seaborn as sns titanic = pd . read _ csv ( ' titanic . csv '
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
titanic pdreadcsvtitaniccsv
firstsouth titanictitanicPclass & titanicEmbarkedS
secondthird titanictitanicPclassisin
snssetthemestyle'whitegrid', colorcodesTrue
snsbarplotx'Sex', y'Survived', datafirstsouth, ciNone
pltsavefigbarpng
snsbarplotx'Pclass', y'Survived', hue'Survived', datasecondthird, ciNone
pltlegendlabels
Keep getting the following error:
Traceback most recent call last:
File usrlocallibpythondistpackagespandascoreindexesbasepy line in getloc
return self.engine.getloccastedkey
File "pandaslibsindexpyx line in pandas.libs.index.IndexEngine.getloc
File "pandaslibsindexpyx line in pandas.libs.index.IndexEngine.getloc
File "pandaslibshashtableclasshelper.pxi", line in pandas.libs.hashtable.PyObjectHashTable.getitem
File "pandaslibshashtableclasshelper.pxi", line in pandas.libs.hashtable.PyObjectHashTable.getitem
KeyError: 'Pclass'
The above exception was the direct cause of the following exception:
Traceback most recent call last:
File homerunnerlocalsubmissionmainpy line in
firstsouth titanictitanicPclass & titanicEmbarkedS
File usrlocallibpythondistpackagespandascoreframepy line in getitem
indexer self.columns.getlockey
File usrlocallibpythondistpackagespandascoreindexesbasepy line in getloc
raise KeyErrorkey from err
KeyError: 'Pclass'
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
