I made the following code that takes out all of the zero's from my df. However when there is a number containing a zero it takes them out as well.
e.g.
3016.2 316.2
0.235 .235
data_usage_df['Data Volume (MB)'] = data_usage_df['Data Volume (MB)'].str.replace('0', '')
Could you help me to figure out how I do an exact match of the cell that equals 0 and replace it with a blank value.
Replace NaN Values with Zero on pandas DataFrame Use the DataFrame. fillna(0) method to replace NaN/None values with the 0 value. It doesn't change the object data but returns a new DataFrame.
Remove rows with all zeros using loc[] in Dataframe We are use Dataframe. loc[] attribute to get the rows which are not zeros. The loc[] is used to get the values based on the mentioned index location.
data_usage_df = data_usage_df.astype(str)
data_usage_df['Data Volume (MB)'].replace(['0', '0.0'], '', inplace=True)
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