pd.date_range Attribute_Error
See original GitHub issueI’m using pandas 0.12 and numpy 1.7.1.
I’m trying to calculate the number of business days between two columns of dates. Not all rows have valid dates though, and pd.date_range does not have an ignore errors option, so I’m getting this error:
In [439]: td = pd.DataFrame({'a':[pd.Timestamp('2010-1-1'), pd.Timestamp('2010-2-1')], 'b':[pd.Timestamp('2010-1-10'), p
d.Timestamp('2010-2-9')]})
In [440]: td.apply(lambda row: len(pd.date_range(row['a'], row['b'], freq='B')), axis=1)
Out[440]:
0 6
1 7
dtype: int64
In [441]: td = pd.DataFrame({'a':[pd.Timestamp('2010-1-1'), pd.Timestamp('2010-2-1')], 'b':[pd.Timestamp('2010-1-10'), p
d.NaT]})
In [442]: td.apply(lambda row: len(pd.date_range(row['a'], row['b'], freq='B')), axis=1)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-442-30b1500c1594> in <module>()
----> 1 td.apply(lambda row: len(pd.date_range(row['a'], row['b'], freq='B')), axis=1)
C:\Python27\lib\site-packages\pandas\core\frame.pyc in apply(self, func, axis, broadcast, raw, args, **kwds)
4414 return self._apply_raw(f, axis)
4415 else:
-> 4416 return self._apply_standard(f, axis)
4417 else:
4418 return self._apply_broadcast(f, axis)
C:\Python27\lib\site-packages\pandas\core\frame.pyc in _apply_standard(self, func, axis, ignore_failures)
4489 # no k defined yet
4490 pass
-> 4491 raise e
4492
4493
AttributeError: ("'NaTType' object has no attribute 'tz'", u'occurred at index 1')
In [443]:
Issue Analytics
- State:
- Created 10 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
pandas.date_range — pandas 1.5.2 documentation
Return a fixed frequency DatetimeIndex. Returns the range of equally spaced time points (where the difference between any two adjacent points is specified...
Read more >pandas - 'module' object has no attribute 'date_range' in python
You can't find date_range because you're using pandas version 0.7.0, which is very old (~9 Feb 2012) in pandas time-- the current stable ......
Read more >Python | pandas.date_range() method - GeeksforGeeks
date_range() is one of the general functions in Pandas which is used to return a fixed frequency DatetimeIndex. Syntax: pandas.date_range(start= ...
Read more >How to Fix: module 'pandas' has no attribute 'dataframe'
One error you may encounter when using pandas is: AttributeError: module 'pandas' has no attribute 'dataframe'.
Read more >Chapter 9: Advanced Data Wrangling With Pandas
AttributeError Traceback (most recent call last) <ipython-input-3-acaefb05bf10> ... Create an array of datetimes with pd.date_range() or pd.period_range().
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
That is quite ineffficient as you’d have to construct the entire series. Try this instead. Period handingling of NaT is not supported currently, but easy enough to roll your own.
see #5203