Skip to content

Commit eb60dae

Browse files
jorisvandenbosscheharisbal
authored and
harisbal
committed
DOC: remove deprecated from_items from dsintro docs (pandas-dev#19837)
1 parent c5631bb commit eb60dae

File tree

2 files changed

+22
-29
lines changed

2 files changed

+22
-29
lines changed

doc/source/dsintro.rst

+13-22
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ and returns a DataFrame. It operates like the ``DataFrame`` constructor except
364364
for the ``orient`` parameter which is ``'columns'`` by default, but which can be
365365
set to ``'index'`` in order to use the dict keys as row labels.
366366

367+
368+
.. ipython:: python
369+
370+
pd.DataFrame.from_dict(dict([('A', [1, 2, 3]), ('B', [4, 5, 6])]))
371+
372+
If you pass ``orient='index'``, the keys will be the row labels. In this
373+
case, you can also pass the desired column names:
374+
375+
.. ipython:: python
376+
377+
pd.DataFrame.from_dict(dict([('A', [1, 2, 3]), ('B', [4, 5, 6])]),
378+
orient='index', columns=['one', 'two', 'three'])
379+
367380
.. _basics.dataframe.from_records:
368381

369382
**DataFrame.from_records**
@@ -378,28 +391,6 @@ dtype. For example:
378391
data
379392
pd.DataFrame.from_records(data, index='C')
380393
381-
.. _basics.dataframe.from_items:
382-
383-
**DataFrame.from_items**
384-
385-
``DataFrame.from_items`` works analogously to the form of the ``dict``
386-
constructor that takes a sequence of ``(key, value)`` pairs, where the keys are
387-
column (or row, in the case of ``orient='index'``) names, and the value are the
388-
column values (or row values). This can be useful for constructing a DataFrame
389-
with the columns in a particular order without having to pass an explicit list
390-
of columns:
391-
392-
.. ipython:: python
393-
394-
pd.DataFrame.from_items([('A', [1, 2, 3]), ('B', [4, 5, 6])])
395-
396-
If you pass ``orient='index'``, the keys will be the row labels. But in this
397-
case you must also pass the desired column names:
398-
399-
.. ipython:: python
400-
401-
pd.DataFrame.from_items([('A', [1, 2, 3]), ('B', [4, 5, 6])],
402-
orient='index', columns=['one', 'two', 'three'])
403394
404395
Column selection, addition, deletion
405396
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

pandas/core/frame.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -1255,12 +1255,14 @@ def to_records(self, index=True, convert_datetime64=True):
12551255

12561256
@classmethod
12571257
def from_items(cls, items, columns=None, orient='columns'):
1258-
"""
1258+
"""Construct a dataframe from a list of tuples
1259+
12591260
.. deprecated:: 0.23.0
1260-
from_items is deprecated and will be removed in a
1261-
future version. Use :meth:`DataFrame.from_dict(dict())`
1262-
instead. :meth:`DataFrame.from_dict(OrderedDict(...))` may be used
1263-
to preserve the key order.
1261+
`from_items` is deprecated and will be removed in a future version.
1262+
Use :meth:`DataFrame.from_dict(dict(items)) <DataFrame.from_dict>`
1263+
instead.
1264+
:meth:`DataFrame.from_dict(OrderedDict(items)) <DataFrame.from_dict>`
1265+
may be used to preserve the key order.
12641266
12651267
Convert (key, value) pairs to DataFrame. The keys will be the axis
12661268
index (usually the columns, but depends on the specified
@@ -1284,8 +1286,8 @@ def from_items(cls, items, columns=None, orient='columns'):
12841286
"""
12851287

12861288
warnings.warn("from_items is deprecated. Please use "
1287-
"DataFrame.from_dict(dict()) instead. "
1288-
"DataFrame.from_dict(OrderedDict()) may be used to "
1289+
"DataFrame.from_dict(dict(items), ...) instead. "
1290+
"DataFrame.from_dict(OrderedDict(items)) may be used to "
12891291
"preserve the key order.",
12901292
FutureWarning, stacklevel=2)
12911293

0 commit comments

Comments
 (0)