Skip to content

Instantly share code, notes, and snippets.

@duaneleem
Last active February 15, 2021 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duaneleem/8b02e25cb28504ba08ded64a6456249b to your computer and use it in GitHub Desktop.
Save duaneleem/8b02e25cb28504ba08ded64a6456249b to your computer and use it in GitHub Desktop.
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