Skip to content

Instantly share code, notes, and snippets.

@duaneleem
Last active Feb 15, 2021
Embed
What would you like to do?
Quick example how to convert a Dataframe/CSV column from HH:MM:SS to minutes.
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