Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas difference between dates

# credit to Stack Overflow user in the source link
import pandas as pd 
# df is your pandas dataframe
# if already datetime64 you don't need to use to_datetime

df['A'] = pd.to_datetime(df['A'])
df['B'] = pd.to_datetime(df['B']) 

df['diff'] =  df['A'] - df['B'] # difference in days
Comment

pandas difference between dates in hours

import pandas
df = pandas.DataFrame(columns=['to','fr','ans'])
df.to = [pandas.Timestamp('2014-01-24 13:03:12.050000'), pandas.Timestamp('2014-01-27 11:57:18.240000'), pandas.Timestamp('2014-01-23 10:07:47.660000')]
df.fr = [pandas.Timestamp('2014-01-26 23:41:21.870000'), pandas.Timestamp('2014-01-27 15:38:22.540000'), pandas.Timestamp('2014-01-23 18:50:41.420000')]
(df.fr-df.to).astype('timedelta64[h]')
Comment

PREVIOUS NEXT
Code Example
Python :: how to iterate tuple in python 
Python :: python string to list without split 
Python :: python sort a list by a custom order 
Python :: iterating over lines in a file 
Python :: python how to add 2 numbers 
Python :: tkinter while button not pressed 
Python :: How to code a simple rock, paper, scissors game on Python 
Python :: loi normale python numpy 
Python :: autopy python not installing 
Python :: python return double quotes instead of single 
Python :: armstrong number function 
Python :: what is manage.py 
Python :: fastest sorting algorithm java 
Python :: data type of none in python 
Python :: Dependency on app with no migrations: 
Python :: how to swap numbers in python mathematically 
Python :: first non repeating charcter in string ython 
Python :: from django.urls import path 
Python :: pandas extracting tables from pdf 
Python :: somalia embassy in bangladesh 
Python :: [1,2,3,4,5] 
Python :: one line try except python 
Python :: pandas numpy multiplicar dos columnas segun una condicion 
Python :: make row readonly tablewidget pyqt 
Python :: python random password generator 
Python :: rabin karp algorithm 
Shell :: chrome inspect devices 
Shell :: rails server already running 
Shell :: check react version 
Shell :: moodle purge from terminal 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =