I am trying to replace the data using Pandas. Following is my aim -
- Remove alphabets from
temperatureandwindspeedcolumns.32 Fwill be replaced by32and6 mphwill be replaced by6. - Convert all negative numbers in
temperatureandwindspeedtoNaN.-99999will be converted toNaN. - Convert all
0ineventtoNo Event
Following is my code
import pandas as pd
import numpy as np
input_data = {'day': ['1/1/2017', '1/4/2017', '1/5/2017', '1/6/2017',
'1/7/2017', '1/8/2017', '1/9/2017', '1/10/2017', '1/11/2017'],
'temperature': ['32 F', -99999, 28, -99999, '32 C', '38 F', 35, 34, 40],
'windspeed': ['6 mph', 9, -99999, 7, -88888, -99999, '10 kmph', 8, 12],
'event': ['Rain', 'Sunny', 'Snow', 0, 'Rain', 'Sunny', 0, 'Cloudy', 'Sunny']
}
weather2 = pd.DataFrame(input_data)
new_weather = weather2.replace({"temperature":{-99999: np.NaN,
-88888: np.NaN,
'[A-Za-z]':''},
"windspeed":{-99999: np.NaN,
-88888: np.NaN,
'[A-Za-z]':''},
"event":{0:'No Event'}},regex=True)
The output is as follows -
Only regex is changed. How can I combine regex with other replace?
