-
-
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.
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