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 = pd.read_csv('titanic.csv')
first_south = titanic[(titanic['Pclass']==1) & (titanic['Embarked']=='S')]
second_third = titanic[titanic['Pclass'].isin([2,3])]
sns.set_theme(style='whitegrid', color_codes=True)
sns.barplot(x='Sex', y='Survived', data=first_south, ci=None)
plt.savefig('bar_1.png')
sns.barplot(x='Pclass', y='Survived', hue='Survived', data=second_third, ci=None)
plt.legend(labels=['0','1'
Keep getting the following error:
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py", line 3621, in get_loc
return self._engine.get_loc(casted_key)
File "pandas/_libs/index.pyx", line 136, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 163, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/hashtable_class_helper.pxi", line 5198, in pandas._libs.hashtable.PyObjectHashTable.get_item
File "pandas/_libs/hashtable_class_helper.pxi", line 5206, in pandas._libs.hashtable.PyObjectHashTable.get_item
KeyError: 'Pclass'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/runner/local/submission/main.py", line 5, in
first_south = titanic[(titanic['Pclass']==1) & (titanic['Embarked']=='S')]
File "/usr/local/lib/python3.10/dist-packages/pandas/core/frame.py", line 3506, in __getitem__
indexer = self.columns.get_loc(key)
File "/usr/local/lib/python3.10/dist-packages/pandas/core/indexes/base.py", line 3623, in get_loc
raise KeyError(key) from err
KeyError: 'Pclass'

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!