Skip to content

DOC: pandas.DateTimeIndex.to_frame #20139

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

Merged
merged 5 commits into from
Mar 16, 2018
Merged

DOC: pandas.DateTimeIndex.to_frame #20139

merged 5 commits into from
Mar 16, 2018

Conversation

ryananyangu
Copy link
Contributor

@ryananyangu ryananyangu commented Mar 10, 2018

Checklist for the pandas documentation sprint (ignore this if you are doing
an unrelated PR):

  • [ X] PR title is "DOC: pandas.DateTimeIndex.to_frame"
  • [X ] The validation script passes: ./scripts/validate_docstrings.py pandas.DatetimeIndex.to_frame
  • [ X] The PEP8 style check passes: git diff upstream/master -u -- "*.py" | flake8 --diff
  • [X ] The html version looks good: python doc/make.py --single pandas.DatetimeIndex.to_frame
  • [ X] It has been proofread on language by another sprint participant

Please include the output of the validation script below between the "```" ticks:

################################################################################
################## Docstring (pandas.DatetimeIndex.to_frame)  ##################
################################################################################

Create a DataFrame with a column containing the Index.

.. versionadded:: 0.21.0

Parameters
----------
index : boolean, default True
    Set the index of the returned DataFrame as the original Index.

Returns
-------
DataFrame
    DataFrame containing the original Index data.

Examples
--------
>>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal')
>>> idx.to_frame()
    animal
animal       
Ant       Ant
Bear     Bear
Cow       Cow

By default, the original Index is reused. To enforce a new Index:

>>> idx.to_frame(index=False)
    animal
0   Ant
1  Bear
2   Cow

Application to datetimes

>>> dt = ['04/27/2008 05:28 AM', '04/22/2008 07:19 AM',
...       '10/09/2008 01:44 PM', '12/25/2008 09:50 AM',
...       '08/19/2008 07:30 PM', '03/07/2008 11:04 PM',
...       '12/22/2008 12:08 PM', '07/01/2008 05:36 AM', 
...       '09/06/2008 04:53 AM', '01/23/2008 07:43 PM']
>>> con_dt = pd.to_datetime(dt)
>>> df = con_dt.to_frame(index=True)
>>> df[0]
2008-04-27 05:28:00   2008-04-27 05:28:00
2008-04-22 07:19:00   2008-04-22 07:19:00
2008-10-09 13:44:00   2008-10-09 13:44:00
2008-12-25 09:50:00   2008-12-25 09:50:00
2008-08-19 19:30:00   2008-08-19 19:30:00
2008-03-07 23:04:00   2008-03-07 23:04:00
2008-12-22 12:08:00   2008-12-22 12:08:00
2008-07-01 05:36:00   2008-07-01 05:36:00
2008-09-06 04:53:00   2008-09-06 04:53:00
2008-01-23 19:43:00   2008-01-23 19:43:00
Name: 0, dtype: datetime64[ns]

See Also
--------
pandas.Series.to_frame : Convert Series to DataFrame

################################################################################
################################## Validation ##################################
################################################################################

Docstring for "pandas.DatetimeIndex.to_frame" correct. :)

If the validation script still gives errors, but you think there is a good reason
to deviate in this case (and there are certainly such cases), please state this
explicitly.

@pep8speaks
Copy link

pep8speaks commented Mar 10, 2018

Hello @ryananyangu! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on March 16, 2018 at 21:20 Hours UTC

@datapythonista
Copy link
Member

@ryananyangu can you edit the title of the PR to be "DOC: pandas.DateTimeIndex.to_frame" instead of "Jovixe"? That'll help us review it. Thanks!

@TomAugspurger TomAugspurger changed the title Jovixe DOC: pandas.DateTimeIndex.to_frame Mar 10, 2018
Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

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

I am personally not really sure about the added value of showing the same but with datetime values.

But the "See Also" is certainly a good addition


See Also
--------
pandas.Series.to_frame : Convert Series to DataFrame
Copy link
Member

Choose a reason for hiding this comment

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

See Also should go before examples. Also, Index also have a .to_series() method that is worth listing here.

I think the preferred option is to avoid using the pandas. prefix in the `See Also section.

2008-07-01 05:36:00 2008-07-01 05:36:00
2008-09-06 04:53:00 2008-09-06 04:53:00
2008-01-23 19:43:00 2008-01-23 19:43:00
Name: 0, dtype: datetime64[ns]
Copy link
Member

Choose a reason for hiding this comment

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

I agree with @jorisvandenbossche, while the example is really nice, it adds a lot of reading for the users for the value it provides. I'd keep the examples as they were.

@codecov
Copy link

codecov bot commented Mar 16, 2018

Codecov Report

Merging #20139 into master will decrease coverage by 0.02%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #20139      +/-   ##
==========================================
- Coverage   91.72%    91.7%   -0.03%     
==========================================
  Files         150      150              
  Lines       49156    49152       -4     
==========================================
- Hits        45090    45074      -16     
- Misses       4066     4078      +12
Flag Coverage Δ
#multiple 90.08% <ø> (-0.03%) ⬇️
#single 41.84% <ø> (-0.01%) ⬇️
Impacted Files Coverage Δ
pandas/core/indexes/base.py 96.66% <ø> (-0.01%) ⬇️
pandas/plotting/_converter.py 65.07% <0%> (-1.74%) ⬇️
pandas/core/base.py 96.78% <0%> (-0.02%) ⬇️
pandas/core/series.py 93.85% <0%> (-0.01%) ⬇️
pandas/core/indexes/multi.py 95.06% <0%> (ø) ⬆️
pandas/core/generic.py 95.84% <0%> (ø) ⬆️
pandas/plotting/_core.py 82.23% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 840d432...366c3ea. Read the comment docs.

@codecov
Copy link

codecov bot commented Mar 16, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@34649f2). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master   #20139   +/-   ##
=========================================
  Coverage          ?    91.7%           
=========================================
  Files             ?      150           
  Lines             ?    49152           
  Branches          ?        0           
=========================================
  Hits              ?    45074           
  Misses            ?     4078           
  Partials          ?        0
Flag Coverage Δ
#multiple 90.08% <ø> (?)
#single 41.84% <ø> (?)
Impacted Files Coverage Δ
pandas/core/indexes/base.py 96.66% <ø> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 34649f2...85f99b0. Read the comment docs.

@TomAugspurger TomAugspurger added this to the 0.23.0 milestone Mar 16, 2018
@TomAugspurger
Copy link
Contributor

Thanks @ryananyangu !

@TomAugspurger TomAugspurger merged commit fb51ca9 into pandas-dev:master Mar 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants