'Bfill not working after changing empty strings to nan
I cant get bfill to work, it continues to be nan after trying to use bfill, here is my code:
import pandas as pd
data_df = pd.read_json("Data_test.json")
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', None)
# Replaces empty strings with nan
df2 = data_df.mask(data_df == "")
#bfill function to fill missing data with prior data.
df2.fillna(method="bfill", inplace=True)
print(df2[["Restaurant", "Food_cat"]])
this is the results i am getting, it continue to be nan, i am trying to use bfill to fill the bottom 2 with "Most Popular" as well.
Restaurant Food_cat
0 McDonald's Most Popular
1 McDonald's Most Popular
2 McDonald's NaN
3 McDonald's NaN
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|