In [50]: df_bank = pd.read_csv ("bank.csv") df_bank.head(10) # do not change this out [50]: age 0 59 1 56 2 41 3 55 4 54 5 42 management single 6 56 management married tertiary 7 8 9 60 37 28 job marital education default balance housing loan contact day month duration campaign pdays previous poutcome deposit admin. married secondary no 2343 yes no unknown 5 unknown unknown technician unknown admin. married secondary married secondary married secondary tertiary no tertiary 45 no 1270 2476 184 services unknown unknown admin. married 0 unknown unknown unknown unknown unknown In [58]: df = df_bank.head(10) married = df['marital'] no retired divorced secondary no technician married secondary no services single secondary no Question 3 ¶ 1. What is the average age for married people in this dataset? --> 958 no average_age_married = married ['age'].mean() print(avg_age_married) # do not change this no 962 963 df['marital'] KeyError Input In [58], in () 1 df df_bank.head(10) 3 married ----> 5 average_age_married = married ['age'].mean() 7 print (avg_age_married) 960 if is hashable(key): 961 830 545 1 5090 return self._get_value(key) . no no unknown yes πιο unknown yes no unknown по no unknown yes yes unknown yes unknown yes yes no unknown yes no unknown yes no unknown 5 5 5 5 5 6 self._check_indexing_error(key) 20 6 6 20 030 6 Traceback (most recent call last) may may may may may may may may may may File ~\anaconda3\lib\site-packages\pandas\core\series.py:958, in Series._getitem_(self, key) 955 return self._values [key] 957 elif key_is_scalar: 1042 1467 1389 579 673 562 1201 1030 608 1297 # otherwise index.get_value will raise InvalidIndexError try: # For labels that don't resolve as scalars like tuples and frozensets --> 389 raise KeyError(key) 390 return super ().get_loc (key, method-method, tolerance-tolerance) KeyError: 'age' 1 1 1 1 2 2 1 1 1 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 File ~\anaconda3\lib\site-packages\pandas\core\series.py: 1069, in series. _get_value(self, label, takeable) 1066 return self._values[label] 1868 # Similar to Index.get_value, but we do not fall back to positional -> 1069 loc= self.index.get_loc(label) 1878 return self.index._get_values_for_loc(self, loc, label) File ~\anaconda3\lib\site-packages\pandas\core\indexes \range.py: 389, in RangeIndex.get_loc(self, key, method, tolerance) 387 raise KeyError (key) from err 388 0 0 0 0 0 0 0 0 0 0 yes yes yes yes yes yes yes yes yes yes
SQL
SQL stands for Structured Query Language, is a form of communication that uses queries structured in a specific format to store, manage & retrieve data from a relational database.
Queries
A query is a type of computer programming language that is used to retrieve data from a database. Databases are useful in a variety of ways. They enable the retrieval of records or parts of records, as well as the performance of various calculations prior to displaying the results. A search query is one type of query that many people perform several times per day. A search query is executed every time you use a search engine to find something. When you press the Enter key, the keywords are sent to the search engine, where they are processed by an algorithm that retrieves related results from the search index. Your query's results are displayed on a search engine results page, or SER.
Why am I getting this error? How can I fix it? please answer this properly
![In [50]: df_bank = pd.read_csv ("bank.csv")
df_bank.head(10) # do not change this
out [50]:
age
0
59
1
56
2
41
3
55
4 54
5 42 management single
6
58 management married
60
37
28
8
9
job marital education default balance housing loan contact day month duration campaign pdays previous poutcome deposit
admin. married secondary no
1042
-1
0
unknown
2343
45
admin. married secondary
yes no unknown 5 may
no no unknown
5 may
5
may
1467
-1
0
unknown
married secondary
yes no unknown
1389
-1
0
unknown
unknown
married secondary
yes
no unknown
5
may
579
-1
0
married
no unknown
5
may
673
-1
0
unknown
yes yes unknown
5
562
0 unknown
may
may
yes yes unknown 6
0 unknown
no unknown 6 may
yes
yes
yes
unknown
unknown
no unknown
6
0
0
0
may
may
no unknown
6
unknown
technician
services
admin.
tertiary
tertiary
tertiary
retired divorced secondary
technician married secondary
services single secondary
In [58]: df = df_bank.head(10)
married = df['marital']
KeyError
Input In [58], in <cell line: 5>()
1 df = df_bank.head(10)
df['marital']
--> 958
no
957 elif key_is_scalar:
962
963
1270
2476
184
0
830
545
1
no 5090
Question 3 ¶
1. What is the average age for married people in this dataset?
no
2 2 2 2
average_age_married = married ['age'].mean()
print(avg_age_married) # do not change this
960 if is hashable(key):
961
no
no
no
3 married
----> 5 average_age_married = married ['age'].mean()
7 print (avg_age_married)
return self._get_value(key)
no
Traceback (most recent call last)
File ~\anaconda3\lib\site-packages\pandas\core\series.py:958, in Series._getitem_(self, key)
955 return self._values [key]
1201
1030
608
1297
# otherwise index.get_value will raise InvalidIndexError
try:
# For labels that don't resolve as scalars like tuples and frozensets
1
1
1
1
2
2
1
-> 1069 loc = self.index.get_loc(label)
1070 return self.index._get_values_for_loc(self, loc, label)
1
1
3
-1
-1
-1
-1
-1
File ~\anaconda3\lib\site-packages\pandas\core\series.py: 1069, in Series._get_value(self, label, takeable)
1066
return self._values[label]
1068 # Similar to Index.get_value, but we do not fall back to positional
File ~\anaconda3\lib\site-packages\pandas\core\indexes \range.py: 389, in RangeIndex.get_loc(self, key, method, tolerance)
387
raise KeyError(key) from err
388
self._check_indexing_error(key)
--> 389
raise KeyError(key)
390 return super ().get_loc (key, method-method, tolerance-tolerance)
KeyError: 'age'
yes
yes
yes
yes
yes
yes
yes
yes
yes
yes](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F60ebc6c2-8d3c-4e68-83cc-52e44d421f5a%2F229971fa-989c-4ee4-8941-cb191da4ff50%2Fuuvrspf_processed.jpeg&w=3840&q=75)
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)