import pandas as pd
import datetime as dt
d = pd.DataFrame([[1, dt.datetime(1990,12,10)],
[2, dt.datetime(1990,12,11)]])
s = d.loc[0].copy()
d == s
TypeError: int() argument must be a string, a bytes-like object or a number, not 'Timestamp'
Problem description
When trying to check if a series is equal to one row in a dataframe containing values of type datetime.datetime
and values of other types, pandas breaks.
It works if the datetime values are substituted with str
type (that's what I have tried, don't know about other types).
Also comparing the .values
works e.g.
d = pd.DataFrame([[1, dt.datetime(1990,12,10)],
[2, dt.datetime(1990,12,11)]])
s = d.loc[0].copy()
d.values == s.values
Works as expected
Expected Output
0 1
0 True True
1 False False
Output of pd.show_versions()
Comment From: pratapvardhan
d.eq(s)
for comparison should work for you.
In [805]: d = pd.DataFrame([[1, dt.datetime(1990,12,10)],
...: [2, dt.datetime(1990,12,11)]])
...: s = d.loc[0].copy()
...:
In [806]: d.eq(s)
Out[806]:
0 1
0 True True
1 False False
Comment From: gionatarogiani
I tried, but it breaks raising the same error
Comment From: pratapvardhan
Check the updated comment. It works fine on master branch. What's the error?
Comment From: jreback
In [7]: d
Out[7]:
0 1
0 1 1990-12-10
1 2 1990-12-11
In [8]: d.eq(s, axis=1)
Out[8]:
0 1
0 True True
1 False False
In [9]: d.eq(s, axis=0)
Out[9]:
0 1
0 True False
1 False False
Comment From: jreback
http://pandas.pydata.org/pandas-docs/stable/basics.html#flexible-comparisons are the docs
Comment From: SimonBaron
@pratapvardhan I aslo see this error in python 2.7 if I run
d = pd.DataFrame([[1, dt.datetime(1990,12,10)],
[2, dt.datetime(1990,12,11)]])
s = d.loc[0].copy()
print d.eq(s)
I get
TypeError: long() argument must be a string or a number, not 'Timestamp'
edit: didn't realise that I'm a version behind on pandas though. still on 19
edit2: updating pandas and datetime doesn't fix this @jreback, axis=0 works as expected, axis=1 gives the error described.
Comment From: gionatarogiani
@SimonBaron Same here, works with axis=0
but not with axis=1
.
I think the problem is that my installed version and the latest available through pip or conda is 0.20.3.
Sorry for opening a issue while working on an old version.