-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set timezone in google takeout. Add util to readers
- Loading branch information
Showing
3 changed files
with
72 additions
and
25 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import re | ||
|
||
def format_column_names(df): | ||
# Replace special characters, including space and ., with _ | ||
# (keeping parenthesis and /, which are used in units, e.g. "temperature (C)") | ||
# Convert to lower case | ||
column_map = {} | ||
for column in df.columns: | ||
formatted_name = column.replace(" ", "_").lower() | ||
formatted_name = re.sub(r'[^a-zA-Z0-9_()/]+', '_', formatted_name) | ||
column_map[column] = formatted_name | ||
df.rename(columns=column_map, inplace=True) | ||
|
||
def set_timezone(df, tz = 'Europe/Helsinki'): | ||
""" Set the timezone of the datetime object in the index column """ | ||
if df.index.tzinfo is None: | ||
df.index = df.index.tz_localize(tz) | ||
return df | ||
|