1.原数据
from collections import *
weather = pd.read_csv('dataset/train_data/city_A/weather.csv',
header=None,
names=['data', 'hour', 'temperature', 'humidity','wind_direction', 'wind_speed', 'wind_force','weather'])
weather=weather.dropna(axis=0,how='any') #drop all rows that have any NaN values
##以下为主要代码
#替换的字典
wind_direction_dict = {'North': 0, 'Northwest': 1, 'East': 2, 'Northeast': 3, 'South': 4, 'Southeast': 5, 'Southwest': 6, 'West': 7, 'Quiet': 8}
wind_speed_dict = {'<12km/h': 0, '16-24km/h': 1, '24-34km/h': 2}
weather_dict = {'Sunny': 0, 'Cloudy': 1, 'Overcast': 2, 'Rain': 3, 'Fog': 4}
#处理过程
weather=weather.replace(wind_direction_dict)
weather=weather.replace(wind_speed_dict)
weather.replace(weather_dict)
处理之后就变这样了,