데이터 전처리 간단 정리
T
TikaToka
missing_values_count = nfl_data.isnull().sum()nfl_data.dropna()subset_nfl_data.fillna(0)
subset_nfl_data.fillna(method='bfill', axis=0).fillna(0)from mlxtend.preprocessing import minmax_scaling
# mix-max scale the data between 0 and 1
scaled_data = minmax_scaling(original_data, columns=[column names])# normalize the exponential data with boxcox
normalized_data = stats.boxcox(original_data)pd.to_datetime(landslides['date']) landslides['date_parsed'].dt.year
landslides['date_parsed'].dt.month
landslides['date_parsed'].dt.day
landslides['date_parsed'].dt.weekday
landslides['date_parsed'].dt.hour
landslides['date_parsed'].dt.minute
landslides['date_parsed'].dt.secondimport fuzzywuzzy
from fuzzywuzzy import process
import charset_normalizer
# get the top 10 closest matches to "south korea"
matches = fuzzywuzzy.process.extract("south korea", countries, limit=10, scorer=fuzzywuzzy.fuzz.token_sort_ratio)
# take a look at them
matches
def replace_matches_in_column(df, column, string_to_match, min_ratio = 47):
# get a list of unique strings
strings = df[column].unique()
# get the top 10 closest matches to our input string
matches = fuzzywuzzy.process.extract(string_to_match, strings,
limit=10, scorer=fuzzywuzzy.fuzz.token_sort_ratio)
# only get matches with a ratio > 90
close_matches = [matches[0] for matches in matches if matches[1] >= min_ratio]
# get the rows of all the close matches in our dataframe
rows_with_matches = df[column].isin(close_matches)
# replace all rows with close matches with the input matches
df.loc[rows_with_matches, column] = string_to_match
# let us know the function's done
print("All done!")