/py-time-to-minutes.py Secret
Last active
February 15, 2021 04:16
Star
You must be signed in to star a gist
Quick example how to convert a Dataframe/CSV column from HH:MM:SS to minutes.
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
import pandas as pd | |
from csv import reader | |
df = pd.read_csv(path_to_download_default_directory + '/test.csv') | |
### Convert entire 'timeColumn' to timedelta type.. | |
df['timeColumn'] = pd.to_timedelta(df['timeColumn']) | |
### Convert 'timeColumn' to minutes only. | |
df['columnAsMinutes'] = df['timeColumn'].dt.total_seconds() / 60 | |
### Drop the old table. | |
df.drop('timeColumn', axis = 1, inplace = True) | |
df.to_csv('newData.csv', index = False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment