Created
June 6, 2021 14:10
-
-
Save AdroitAnandAI/21a8cc0812ca0a6b71774b7370881a97 to your computer and use it in GitHub Desktop.
Data Transformations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_to_date(date): | |
date_as_string = str(date) | |
date_as_string = date_as_string[2:] | |
date_time_obj = datetime.strptime(date_as_string, '%y%m%d') | |
return date_time_obj | |
def convert_to_daynum(date): | |
date_as_string = str(date) | |
date_as_string = date_as_string[2:] | |
date_time_obj = datetime.strptime(date_as_string, '%y%m%d') | |
return date_time_obj.timetuple().tm_yday | |
df['day'] = df['date'].apply(convert_to_daynum) | |
df['date'] = df['date'].apply(convert_to_date) | |
df['year'] = df['date'].apply(lambda x: x.year) | |
df['week'] = df['date'].apply(lambda x: x.week) | |
df['month'] = df['date'].apply(lambda x: x.month) | |
df['dayinmonth'] = df['date'].apply(lambda x: x.day) | |
df['humScale'] = df['temp'] * df['rainfall'] | |
df.sort_values('date', inplace=True, ascending=True) | |
df=df.loc[:,['week', 'temp', 'wind', 'rainfall', 'day', 'humScale', 'humidity']] | |
df = df.reset_index(drop=True) | |
df.head(10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment