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
Step by step
Solved in 3 steps with 1 images