I have a Python dataframe with a column called 'avg_snow' that is completely blank when I output the table to a CSV file.
I want to fill in the blank rows with the value 0 (datatype float). I have tried the following, but it gives me an error.
merged_left_1 = merged_left_1['avg_snow'].replace('', 0, inplace = True)
This is the error message I get:
TypeError: 'NoneType' object is not subscriptable
You can do that in multiple ways. I am creating a dummy dataframe to show you how it works:
df = pd.DataFrame(data=[None,None,None],columns=['a'])
One way is:
df['a'] = 0 # Use this if entire columns values are None.
Or a better way to do is by using pandas
' fillna
:
df.a.fillna(value=0, inplace=True) # This fills all the null values in the columns with 0.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With