Skip to content

Commit c25f3af

Browse files
committed
issue pandas-dev#48674 index constructor updates to the frame.py file
1 parent ee352b1 commit c25f3af

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ doc/build/html/index.html
121121
# Windows specific leftover:
122122
doc/tmp.sv
123123
env/
124+
pandas-env
124125
doc/source/savefig/
125126

126127
# Interactive terminal generated files #

pandas/core/frame.py

+21-1
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,8 @@ class DataFrame(NDFrame, OpsMixin):
490490
data : ndarray (structured or homogeneous), Iterable, dict, or DataFrame
491491
Dict can contain Series, arrays, constants, dataclass or list-like objects. If
492492
data is a dict, column order follows insertion-order. If a dict contains Series
493-
which have an index defined, it is aligned by its index.
493+
which have an index defined, it is aligned by its index. This alignment also occurs
494+
if data is a Series or a DataFrame itself. Alignment is done on Series/DataFrame inputs.
494495
495496
.. versionchanged:: 0.25.0
496497
If data is a list of dicts, column order follows insertion-order.
@@ -592,6 +593,25 @@ class DataFrame(NDFrame, OpsMixin):
592593
0 0 0
593594
1 0 3
594595
2 2 3
596+
597+
Constructing DataFrame from Series/DataFrame:
598+
599+
>>> ser = pd.Series([1, 2, 3], index=["a", "b", "c"])
600+
>>> df = pd.DataFrame(data=ser, index=["a", "c"])
601+
>>> print(df)
602+
603+
0
604+
a 1
605+
c 3
606+
607+
>>> df1 = pd.DataFrame([1, 2, 3], index=["a", "b", "c"], columns=["x"])
608+
>>> df2 = pd.DataFrame(data=df1, index=["a", "c"])
609+
>>> print(df2)
610+
611+
x
612+
a 1
613+
c 3
614+
595615
"""
596616

597617
_internal_names_set = {"columns", "index"} | NDFrame._internal_names_set

0 commit comments

Comments
 (0)