8000 DOC: update DataFrame.to_records by samuelsinayoko · Pull Request #20191 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

DOC: update DataFrame.to_records #20191

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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

8000
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix html docs.
Missing newlines.
  • Loading branch information
samuelsinayoko committed Mar 10, 2018
commit 8d0ee562757d4addb713fa1080225a2f21ab7f35
6 changes: 5 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ def to_records(self, index=True, convert_datetime64=True):

Examples
--------

Copy link
Contributor

Choose a reason for hiding this comment

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

No blank line here

Copy link
Contributor Author
@samuelsinayoko samuelsinayoko Mar 10, 2018

Choose a reason for hiding this comment

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

Fixed in 2d0a3bb.

>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [0.5, 0.75]}, index=['a', 'b'])
>>> df
col1 col2
Expand All @@ -1241,11 +1242,13 @@ def to_records(self, index=True, convert_datetime64=True):
dtype=[('index', 'O'), ('col1', '<i8'), ('col2', '<f8')])

The index can be excluded from the record array:

>>> df.to_records(index=False)
rec.array([(1, 0.5 ), (2, 0.75)],
dtype=[('col1', '<i8'), ('col2', '<f8')])

By default, timestamps are converted to `datetime.datetime` objects
By default, timestamps are converted to `datetime.datetime` objects:

>>> df.index = pd.date_range('2018-01-01 09:00', periods=2, freq='min')
>>> df
col1 col2
Expand All @@ -1257,6 +1260,7 @@ def to_records(self, index=True, convert_datetime64=True):
dtype=[('index', 'O'), ('col1', '<i8'), ('col2', '<f8')])

The timestamp conversion can be disabled to use NumPy datetime64 objects instead:

>>> df.to_records(convert_datetime64=False)
rec.array([('2018-01-01T09:00:00.000000000', 1, 0.5 ),
('2018-01-01T09:01:00.000000000', 2, 0.75)],
Expand Down
0