@@ -483,7 +483,7 @@ def axes(self):
483
483
--------
484
484
>>> df = pd.DataFrame({'col1': [1, 2], 'col2': [3, 4]})
485
485
>>> df.axes
486
- [RangeIndex(start=0, stop=2, step=1), Index(['coll ', 'col2'],
486
+ [RangeIndex(start=0, stop=2, step=1), Index(['col1 ', 'col2'],
487
487
dtype='object')]
488
488
"""
489
489
return [self .index , self .columns ]
@@ -3016,28 +3016,30 @@ def query(self, expr, inplace=False, **kwargs):
3016
3016
3017
3017
Parameters
3018
3018
----------
3019
- expr : string
3019
+ expr : str
3020
3020
The query string to evaluate. You can refer to variables
3021
3021
in the environment by prefixing them with an '@' character like
3022
3022
``@a + b``.
3023
3023
inplace : bool
3024
3024
Whether the query should modify the data in place or return
3025
- a modified copy
3026
-
3027
- .. versionadded:: 0.18.0
3028
-
3029
- kwargs : dict
3025
+ a modified copy.
3026
+ **kwargs
3030
3027
See the documentation for :func:`pandas.eval` for complete details
3031
3028
on the keyword arguments accepted by :meth:`DataFrame.query`.
3032
3029
3030
+ .. versionadded:: 0.18.0
3031
+
3033
3032
Returns
3034
3033
-------
3035
- q : DataFrame
3034
+ DataFrame
3035
+ DataFrame resulting from the provided query expression.
3036
3036
3037
3037
See Also
3038
3038
--------
3039
- pandas.eval
3040
- DataFrame.eval
3039
+ eval : Evaluate a string describing operations on
3040
+ DataFrame columns.
3041
+ DataFrame.eval : Evaluate a string describing operations on
3042
+ DataFrame columns.
3041
3043
3042
3044
Notes
3043
3045
-----
@@ -3076,9 +3078,23 @@ def query(self, expr, inplace=False, **kwargs):
3076
3078
3077
3079
Examples
3078
3080
--------
3079
- >>> df = pd.DataFrame(np.random.randn(10, 2), columns=list('ab'))
3080
- >>> df.query('a > b')
3081
- >>> df[df.a > df.b] # same result as the previous expression
3081
+ >>> df = pd.DataFrame({'A': range(1, 6), 'B': range(10, 0, -2)})
3082
+ >>> df
3083
+ A B
3084
+ 0 1 10
3085
+ 1 2 8
3086
+ 2 3 6
3087
+ 3 4 4
3088
+ 4 5 2
3089
+ >>> df.query('A > B')
3090
+ A B
3091
+ 4 5 2
3092
+
3093
+ The previous expression is equivalent to
3094
+
3095
+ >>> df[df.A > df.B]
3096
+ A B
3097
+ 4 5 2
3082
3098
"""
3083
3099
inplace = validate_bool_kwarg (inplace , 'inplace' )
3084
3100
if not isinstance (expr , compat .string_types ):
@@ -5142,8 +5158,7 @@ def _combine_const(self, other, func):
5142
5158
5143
5159
def combine (self , other , func , fill_value = None , overwrite = True ):
5144
5160
"""
5145
- Perform column-wise combine with another DataFrame based on a
5146
- passed function.
5161
+ Perform column-wise combine with another DataFrame.
5147
5162
5148
5163
Combines a DataFrame with `other` DataFrame using `func`
5149
5164
to element-wise combine columns. The row and column indexes of the
@@ -5159,13 +5174,14 @@ def combine(self, other, func, fill_value=None, overwrite=True):
5159
5174
fill_value : scalar value, default None
5160
5175
The value to fill NaNs with prior to passing any column to the
5161
5176
merge func.
5162
- overwrite : boolean , default True
5177
+ overwrite : bool , default True
5163
5178
If True, columns in `self` that do not exist in `other` will be
5164
5179
overwritten with NaNs.
5165
5180
5166
5181
Returns
5167
5182
-------
5168
- result : DataFrame
5183
+ DataFrame
5184
+ Combination of the provided DataFrames.
5169
5185
5170
5186
See Also
5171
5187
--------
@@ -5209,15 +5225,15 @@ def combine(self, other, func, fill_value=None, overwrite=True):
5209
5225
>>> df1 = pd.DataFrame({'A': [0, 0], 'B': [None, 4]})
5210
5226
>>> df2 = pd.DataFrame({'A': [1, 1], 'B': [None, 3]})
5211
5227
>>> df1.combine(df2, take_smaller, fill_value=-5)
5212
- A B
5213
- 0 0 NaN
5228
+ A B
5229
+ 0 0 -5.0
5214
5230
1 0 3.0
5215
5231
5216
5232
Example that demonstrates the use of `overwrite` and behavior when
5217
5233
the axis differ between the dataframes.
5218
5234
5219
5235
>>> df1 = pd.DataFrame({'A': [0, 0], 'B': [4, 4]})
5220
- >>> df2 = pd.DataFrame({'B': [3, 3], 'C': [-10, 1],}, index=[1, 2])
5236
+ >>> df2 = pd.DataFrame({'B': [3, 3], 'C': [-10, 1], }, index=[1, 2])
5221
5237
>>> df1.combine(df2, take_smaller)
5222
5238
A B C
5223
5239
0 NaN NaN NaN
@@ -5232,7 +5248,7 @@ def combine(self, other, func, fill_value=None, overwrite=True):
5232
5248
5233
5249
Demonstrating the preference of the passed in dataframe.
5234
5250
5235
- >>> df2 = pd.DataFrame({'B': [3, 3], 'C': [1, 1],}, index=[1, 2])
5251
+ >>> df2 = pd.DataFrame({'B': [3, 3], 'C': [1, 1], }, index=[1, 2])
5236
5252
>>> df2.combine(df1, take_smaller)
5237
5253
A B C
5238
5254
0 0.0 NaN NaN
@@ -5716,19 +5732,19 @@ def pivot(self, index=None, columns=None, values=None):
5716
5732
5717
5733
This first example aggregates values by taking the sum.
5718
5734
5719
- >>> table = pivot_table(df, values='D', index=['A', 'B'],
5735
+ >>> table = pd. pivot_table(df, values='D', index=['A', 'B'],
5720
5736
... columns=['C'], aggfunc=np.sum)
5721
5737
>>> table
5722
5738
C large small
5723
5739
A B
5724
- bar one 4 5
5725
- two 7 6
5726
- foo one 4 1
5727
- two NaN 6
5740
+ bar one 4.0 5.0
5741
+ two 7.0 6.0
5742
+ foo one 4.0 1.0
5743
+ two NaN 6.0
5728
5744
5729
5745
We can also fill missing values using the `fill_value` parameter.
5730
5746
5731
- >>> table = pivot_table(df, values='D', index=['A', 'B'],
5747
+ >>> table = pd. pivot_table(df, values='D', index=['A', 'B'],
5732
5748
... columns=['C'], aggfunc=np.sum, fill_value=0)
5733
5749
>>> table
5734
5750
C large small
@@ -5740,12 +5756,11 @@ def pivot(self, index=None, columns=None, values=None):
5740
5756
5741
5757
The next example aggregates by taking the mean across multiple columns.
5742
5758
5743
- >>> table = pivot_table(df, values=['D', 'E'], index=['A', 'C'],
5759
+ >>> table = pd. pivot_table(df, values=['D', 'E'], index=['A', 'C'],
5744
5760
... aggfunc={'D': np.mean,
5745
5761
... 'E': np.mean})
5746
5762
>>> table
5747
- D E
5748
- mean mean
5763
+ D E
5749
5764
A C
5750
5765
bar large 5.500000 7.500000
5751
5766
small 5.500000 8.500000
@@ -5755,17 +5770,17 @@ def pivot(self, index=None, columns=None, values=None):
5755
5770
We can also calculate multiple types of aggregations for any given
5756
5771
value column.
5757
5772
5758
- >>> table = pivot_table(df, values=['D', 'E'], index=['A', 'C'],
5773
+ >>> table = pd. pivot_table(df, values=['D', 'E'], index=['A', 'C'],
5759
5774
... aggfunc={'D': np.mean,
5760
5775
... 'E': [min, max, np.mean]})
5761
5776
>>> table
5762
- D E
5763
- mean max mean min
5777
+ D E
5778
+ mean max mean min
5764
5779
A C
5765
- bar large 5.500000 9 7.500000 6
5766
- small 5.500000 9 8.500000 8
5767
- foo large 2.000000 5 4.500000 4
5768
- small 2.333333 6 4.333333 2
5780
+ bar large 5.500000 9.0 7.500000 6.0
5781
+ small 5.500000 9.0 8.500000 8.0
5782
+ foo large 2.000000 5.0 4.500000 4.0
5783
+ small 2.333333 6.0 4.333333 2.0
5769
5784
"""
5770
5785
5771
5786
@Substitution ('' )
@@ -6903,41 +6918,67 @@ def round(self, decimals=0, *args, **kwargs):
6903
6918
columns not included in `decimals` will be left as is. Elements
6904
6919
of `decimals` which are not columns of the input will be
6905
6920
ignored.
6921
+ *args
6922
+ Additional keywords have no effect but might be accepted for
6923
+ compatibility with numpy.
6924
+ **kwargs
6925
+ Additional keywords have no effect but might be accepted for
6926
+ compatibility with numpy.
6906
6927
6907
6928
Returns
6908
6929
-------
6909
- DataFrame
6930
+ DataFrame :
6931
+ A DataFrame with the affected columns rounded to the specified
6932
+ number of decimal places.
6910
6933
6911
6934
See Also
6912
6935
--------
6913
- numpy.around
6914
- Series.round
6936
+ numpy.around : Round a numpy array to the given number of decimals.
6937
+ Series.round : Round a Series to the given number of decimals.
6915
6938
6916
6939
Examples
6917
6940
--------
6918
- >>> df = pd.DataFrame(np.random.random([3, 3]) ,
6919
- ... columns=['A', 'B', 'C'], index =['first ', 'second', 'third '])
6941
+ >>> df = pd.DataFrame([(.21, .32), (.01, .67), (.66, .03), (.21, .18)] ,
6942
+ ... columns =['dogs ', 'cats '])
6920
6943
>>> df
6921
- A B C
6922
- first 0.028208 0.992815 0.173891
6923
- second 0.038683 0.645646 0.577595
6924
- third 0.877076 0.149370 0.491027
6925
- >>> df.round(2)
6926
- A B C
6927
- first 0.03 0.99 0.17
6928
- second 0.04 0.65 0.58
6929
- third 0.88 0.15 0.49
6930
- >>> df.round({'A': 1, 'C': 2})
6931
- A B C
6932
- first 0.0 0.992815 0.17
6933
- second 0.0 0.645646 0.58
6934
- third 0.9 0.149370 0.49
6935
- >>> decimals = pd.Series([1, 0, 2], index=['A', 'B', 'C'])
6944
+ dogs cats
6945
+ 0 0.21 0.32
6946
+ 1 0.01 0.67
6947
+ 2 0.66 0.03
6948
+ 3 0.21 0.18
6949
+
6950
+ By providing an integer each column is rounded to the same number
6951
+ of decimal places
6952
+
6953
+ >>> df.round(1)
6954
+ dogs cats
6955
+ 0 0.2 0.3
6956
+ 1 0.0 0.7
6957
+ 2 0.7 0.0
6958
+ 3 0.2 0.2
6959
+
6960
+ With a dict, the number of places for specific columns can be
6961
+ specfified with the column names as key and the number of decimal
6962
+ places as value
6963
+
6964
+ >>> df.round({'dogs': 1, 'cats': 0})
6965
+ dogs cats
6966
+ 0 0.2 0.0
6967
+ 1 0.0 1.0
6968
+ 2 0.7 0.0
6969
+ 3 0.2 0.0
6970
+
6971
+ Using a Series, the number of places for specific columns can be
6972
+ specfified with the column names as index and the number of
6973
+ decimal places as value
6974
+
6975
+ >>> decimals = pd.Series([0, 1], index=['cats', 'dogs'])
6936
6976
>>> df.round(decimals)
6937
- A B C
6938
- first 0.0 1 0.17
6939
- second 0.0 1 0.58
6940
- third 0.9 0 0.49
6977
+ dogs cats
6978
+ 0 0.2 0.0
6979
+ 1 0.0 1.0
6980
+ 2 0.7 0.0
6981
+ 3 0.2 0.0
6941
6982
"""
6942
6983
from pandas .core .reshape .concat import concat
6943
6984
0 commit comments