@@ -119,40 +119,41 @@ def __add__(self, other):
119
119
120
120
Examples
121
121
--------
122
- >>> df = pd.DataFrame({'height': [1.5, 2.6], 'weight': [500, 800]},
123
- ... index=['elk', 'moose'])
122
+ >>> df = pd.DataFrame(
123
+ ... {"height": [1.5, 2.6], "weight": [500, 800]}, index=["elk", "moose"]
124
+ ... )
124
125
>>> df
125
126
height weight
126
127
elk 1.5 500
127
128
moose 2.6 800
128
129
129
130
Adding a scalar affects all rows and columns.
130
131
131
- >>> df[[' height', ' weight' ]] + 1.5
132
+ >>> df[[" height", " weight" ]] + 1.5
132
133
height weight
133
134
elk 3.0 501.5
134
135
moose 4.1 801.5
135
136
136
137
Each element of a list is added to a column of the DataFrame, in order.
137
138
138
- >>> df[[' height', ' weight' ]] + [0.5, 1.5]
139
+ >>> df[[" height", " weight" ]] + [0.5, 1.5]
139
140
height weight
140
141
elk 2.0 501.5
141
142
moose 3.1 801.5
142
143
143
144
Keys of a dictionary are aligned to the DataFrame, based on column names;
144
145
each value in the dictionary is added to the corresponding column.
145
146
146
- >>> df[[' height', ' weight' ]] + {' height' : 0.5, ' weight' : 1.5}
147
+ >>> df[[" height", " weight" ]] + {" height" : 0.5, " weight" : 1.5}
147
148
height weight
148
149
elk 2.0 501.5
149
150
moose 3.1 801.5
150
151
151
152
When `other` is a :class:`Series`, the index of `other` is aligned with the
152
153
columns of the DataFrame.
153
154
154
- >>> s1 = pd.Series([0.5, 1.5], index=[' weight', ' height' ])
155
- >>> df[[' height', ' weight' ]] + s1
155
+ >>> s1 = pd.Series([0.5, 1.5], index=[" weight", " height" ])
156
+ >>> df[[" height", " weight" ]] + s1
156
157
height weight
157
158
elk 3.0 500.5
158
159
moose 4.1 800.5
@@ -161,23 +162,24 @@ def __add__(self, other):
161
162
the :class:`Series` will not be reoriented. If index-wise alignment is desired,
162
163
:meth:`DataFrame.add` should be used with `axis='index'`.
163
164
164
- >>> s2 = pd.Series([0.5, 1.5], index=[' elk', ' moose' ])
165
- >>> df[[' height', ' weight' ]] + s2
165
+ >>> s2 = pd.Series([0.5, 1.5], index=[" elk", " moose" ])
166
+ >>> df[[" height", " weight" ]] + s2
166
167
elk height moose weight
167
168
elk NaN NaN NaN NaN
168
169
moose NaN NaN NaN NaN
169
170
170
- >>> df[[' height', ' weight' ]].add(s2, axis=' index' )
171
+ >>> df[[" height", " weight" ]].add(s2, axis=" index" )
171
172
height weight
172
173
elk 2.0 500.5
173
174
moose 4.1 801.5
174
175
175
176
When `other` is a :class:`DataFrame`, both columns names and the
176
177
index are aligned.
177
178
178
- >>> other = pd.DataFrame({'height': [0.2, 0.4, 0.6]},
179
- ... index=['elk', 'moose', 'deer'])
180
- >>> df[['height', 'weight']] + other
179
+ >>> other = pd.DataFrame(
180
+ ... {"height": [0.2, 0.4, 0.6]}, index=["elk", "moose", "deer"]
181
+ ... )
182
+ >>> df[["height", "weight"]] + other
181
183
height weight
182
184
deer NaN NaN
183
185
elk 1.7 NaN
0 commit comments