Skip to main content

Posts

Showing posts with the label 26.Replace all negative values in a data frame with a 0.

ads1

26.Replace all negative values in a data frame with a 0.

  26.Replace all negative values in a data frame with a 0. Solution :- import pandas as pd data = {'sales1':[10,20,-4,5,-1,15], 'sales2':[20,15,10,-1,12,-2]} df = pd.DataFrame(data) print("Data Frame") print(df) print('Display DataFrame after replacing every negative value with 0') df[df<0]=0 print(df) Output :- 

ads2