Skip to content

DOC: more pd.to_datetime examples #13004

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,7 @@ Upsampling
Resampler.pad
Resampler.fillna
Resampler.asfreq
Resampler.interpolate

Computations / Descriptive Stats
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3446,8 +3446,6 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
return self._constructor(new_data).__finalize__(self)

_shared_docs['interpolate'] = """
Interpolate values according to different methods.

Please note that only ``method='linear'`` is supported for
DataFrames/Series with a MultiIndex.

Expand Down Expand Up @@ -3523,6 +3521,10 @@ def replace(self, to_replace=None, value=None, inplace=False, limit=None,
@Appender(_shared_docs['interpolate'] % _shared_doc_kwargs)
def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
limit_direction='forward', downcast=None, **kwargs):
"""
Interpolate values according to different methods.
"""

if self.ndim > 2:
raise NotImplementedError("Interpolate has not been implemented "
"on Panel and Panel 4D objects.")
Expand Down
2 changes: 2 additions & 0 deletions pandas/tseries/resample.py
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,8 @@ def fillna(self, method, limit=None):
def interpolate(self, method='linear', axis=0, limit=None, inplace=False,
limit_direction='forward', downcast=None, **kwargs):
"""
Interpolate values according to different methods.

.. versionadded:: 0.18.1
"""
result = self._upsample(None)
Expand Down
23 changes: 22 additions & 1 deletion pandas/tseries/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,33 @@ def to_datetime(arg, errors='raise', dayfirst=False, yearfirst=False,
1 2016-03-05
dtype: datetime64[ns]

Date that does not meet timestamp limitations:
If a date that does not meet timestamp limitations, passing errors='coerce'
will force to NaT. Furthermore this will force non-dates to NaT as well.

>>> pd.to_datetime('13000101', format='%Y%m%d')
datetime.datetime(1300, 1, 1, 0, 0)
>>> pd.to_datetime('13000101', format='%Y%m%d', errors='coerce')
NaT

Passing infer_datetime_format=True can often-times speedup a parsing
if its not an ISO8601 format exactly, but in a regular format.

>>> s = pd.Series(['3/11/2000', '3/12/2000', '3/13/2000']*1000)

>>> s.head()
0 3/11/2000
1 3/12/2000
2 3/13/2000
3 3/11/2000
4 3/12/2000
dtype: object

>>> %timeit pd.to_datetime(s,infer_datetime_format=True)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this legit to do here?

100 loops, best of 3: 10.4 ms per loop

>>> %timeit pd.to_datetime(s,infer_datetime_format=False)
1 loop, best of 3: 471 ms per loop

"""
return _to_datetime(arg, errors=errors, dayfirst=dayfirst,
yearfirst=yearfirst,
Expand Down