Pandas fillna throws ValueError: fill value must be in categories

Use Series.cat.add_categories for add categories first: AM_train[‘product_category_2’] = AM_train[‘product_category_2’].cat.add_categories(‘Unknown’) AM_train[‘product_category_2’].fillna(‘Unknown’, inplace =True) AM_train[‘city_development_index’] = AM_train[‘city_development_index’].cat.add_categories(‘Missing’) AM_train[‘city_development_index’].fillna(‘Missing’, inplace =True) Sample: AM_train = pd.DataFrame({‘product_category_2’: pd.Categorical([‘a’,’b’,np.nan])}) AM_train[‘product_category_2’] = AM_train[‘product_category_2’].cat.add_categories(‘Unknown’) AM_train[‘product_category_2’].fillna(‘Unknown’, inplace =True) print (AM_train) product_category_2 0 a 1 b 2 Unknown

Replace NaN in one column with value from corresponding row of second column

Assuming your DataFrame is in df: df.Temp_Rating.fillna(df.Farheit, inplace=True) del df[‘Farheit’] df.columns=”File heat Observations”.split() First replace any NaN values with the corresponding value of df.Farheit. Delete the ‘Farheit’ column. Then rename the columns. Here’s the resulting DataFrame: File heat Observations 0 1 YesQ 75 1 1 NoR 115 2 1 YesA 63 3 1 NoT 41 … Read more

Pandas fill missing values in dataframe from another dataframe

If you have two DataFrames of the same shape, then: df[df.isnull()] = d2 Will do the trick. Only locations where df.isnull() evaluates to True (highlighted in green) will be eligible for assignment. In practice, the DataFrames aren’t always the same size / shape, and transforming methods (especially .shift()) are useful. Data coming in is invariably … Read more

Python Pandas replace NaN in one column with value from corresponding row of second column

Assuming your DataFrame is in df: df.Temp_Rating.fillna(df.Farheit, inplace=True) del df[‘Farheit’] df.columns=”File heat Observations”.split() First replace any NaN values with the corresponding value of df.Farheit. Delete the ‘Farheit’ column. Then rename the columns. Here’s the resulting DataFrame:

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)