DOsinga / deep_learning_cookbook

Deep Learning Cookbox
Apache License 2.0
686 stars 335 forks source link

06.1 Question matching -- KeyError: "None of ['Id'] are in the columns" #69

Open mikechen66 opened 4 years ago

mikechen66 commented 4 years ago

Dear Douwe

There is a None of ['Id'] issue. Please help solve the issue.

df = pd.DataFrame.from_records(rows)
df = df.set_index('Id', drop=False) df['Title'] = df['Title'].fillna('').astype('str') df['Tags'] = df['Tags'].fillna('').astype('str') df['Body'] = df['Body'].fillna('').astype('str') df['Id'] = df['Id'].astype('int') df['PostTypeId'] = df['PostTypeId'].astype('int') df['ViewCount'] = df['ViewCount'].astype('float')

df.head()


KeyError Traceback (most recent call last)

in 1 df = pd.DataFrame.from_records(rows) ----> 2 df = df.set_index('Id', drop=False) 3 df['Title'] = df['Title'].fillna('').astype('str') 4 df['Tags'] = df['Tags'].fillna('').astype('str') 5 df['Body'] = df['Body'].fillna('').astype('str') /usr/local/lib/python3.6/dist-packages/pandas/core/frame.py in set_index(self, keys, drop, append, inplace, verify_integrity) 4301 4302 if missing: -> 4303 raise KeyError(f"None of {missing} are in the columns") 4304 4305 if inplace: KeyError: "None of ['Id'] are in the columns"