File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -766,6 +766,26 @@ This is like an ``append`` operation on the ``DataFrame``.
766
766
dfi.loc[3 ] = 5
767
767
dfi
768
768
769
+ When assigning a :class: `Series ` to a column, values are **aligned on index labels **.
770
+ The order of the ``Series `` does not matter. Labels not present in the
771
+ ``DataFrame `` index result in ``NaN ``.
772
+
773
+ .. ipython :: python
774
+
775
+ import pandas as pd
776
+
777
+ df = pd.DataFrame({" a" : [1 , 2 , 3 ]})
778
+ df
779
+
780
+ # assigning a partial Series aligns by index; other rows become NaN
781
+ df[" b" ] = pd.Series({1 : " b" })
782
+ df
783
+
784
+ # order of the Series is irrelevant; labels drive the alignment
785
+ s = pd.Series({2 : " zero" , 1 : " one" , 0 : " two" })
786
+ df[" c" ] = s
787
+ df
788
+
769
789
.. _indexing.basics.get_value :
770
790
771
791
Fast scalar value getting and setting
You can’t perform that action at this time.
0 commit comments