@@ -210,7 +210,7 @@ as an attribute:
210210 See `here for an explanation of valid identifiers
211211 <https://docs.python.org/3/reference/lexical_analysis.html#identifiers> `__.
212212
213- - The attribute will not be available if it conflicts with an existing method name, e.g. ``s.min `` is not allowed.
213+ - The attribute will not be available if it conflicts with an existing method name, e.g. ``s.min `` is not allowed, but `` s['min'] `` is possible .
214214
215215 - Similarly, the attribute will not be available if it conflicts with any of the following list: ``index ``,
216216 ``major_axis ``, ``minor_axis ``, ``items ``.
@@ -540,7 +540,7 @@ The ``callable`` must be a function with one argument (the calling Series or Dat
540540 columns = list (' ABCD' ))
541541 df1
542542
543- df1.loc[lambda df : df.A > 0 , :]
543+ df1.loc[lambda df : df[ ' A ' ] > 0 , :]
544544 df1.loc[:, lambda df : [' A' , ' B' ]]
545545
546546 df1.iloc[:, lambda df : [0 , 1 ]]
@@ -552,7 +552,7 @@ You can use callable indexing in ``Series``.
552552
553553.. ipython :: python
554554
555- df1.A .loc[lambda s : s > 0 ]
555+ df1[ ' A ' ] .loc[lambda s : s > 0 ]
556556
557557 Using these methods / indexers, you can chain data selection operations
558558without using a temporary variable.
@@ -561,7 +561,7 @@ without using a temporary variable.
561561
562562 bb = pd.read_csv(' data/baseball.csv' , index_col = ' id' )
563563 (bb.groupby([' year' , ' team' ]).sum()
564- .loc[lambda df : df.r > 100 ])
564+ .loc[lambda df : df[ ' r ' ] > 100 ])
565565
566566 .. _indexing.deprecate_ix :
567567
@@ -871,9 +871,9 @@ Boolean indexing
871871Another common operation is the use of boolean vectors to filter the data.
872872The operators are: ``| `` for ``or ``, ``& `` for ``and ``, and ``~ `` for ``not ``.
873873These **must ** be grouped by using parentheses, since by default Python will
874- evaluate an expression such as ``df.A > 2 & df.B < 3 `` as
875- ``df.A > (2 & df.B ) < 3 ``, while the desired evaluation order is
876- ``(df. A > 2) & (df.B < 3) ``.
874+ evaluate an expression such as ``df['A'] > 2 & df['B'] < 3 `` as
875+ ``df['A'] > (2 & df['B'] ) < 3 ``, while the desired evaluation order is
876+ ``(df[' A > 2) & (df['B'] < 3) ``.
877877
878878Using a boolean vector to index a Series works exactly as in a NumPy ndarray:
879879
@@ -1134,7 +1134,7 @@ between the values of columns ``a`` and ``c``. For example:
11341134 df
11351135
11361136 # pure python
1137- df[(df.a < df.b ) & (df.b < df.c )]
1137+ df[(df[ ' a ' ] < df[ ' b ' ] ) & (df[ ' b ' ] < df[ ' c ' ] )]
11381138
11391139 # query
11401140 df.query(' (a < b) & (b < c)' )
@@ -1241,7 +1241,7 @@ Full numpy-like syntax:
12411241 df = pd.DataFrame(np.random.randint(n, size = (n, 3 )), columns = list (' abc' ))
12421242 df
12431243 df.query(' (a < b) & (b < c)' )
1244- df[(df.a < df.b ) & (df.b < df.c )]
1244+ df[(df[ ' a ' ] < df[ ' b ' ] ) & (df[ ' b ' ] < df[ ' c ' ] )]
12451245
12461246 Slightly nicer by removing the parentheses (by binding making comparison
12471247operators bind tighter than ``& `` and ``| ``).
@@ -1279,12 +1279,12 @@ The ``in`` and ``not in`` operators
12791279 df.query(' a in b' )
12801280
12811281 # How you'd do it in pure Python
1282- df[df.a .isin(df.b )]
1282+ df[df[ ' a ' ] .isin(df[ ' b ' ] )]
12831283
12841284 df.query(' a not in b' )
12851285
12861286 # pure Python
1287- df[~ df.a .isin(df.b )]
1287+ df[~ df[ ' a ' ] .isin(df[ ' b ' ] )]
12881288
12891289
12901290 You can combine this with other expressions for very succinct queries:
@@ -1297,7 +1297,7 @@ You can combine this with other expressions for very succinct queries:
12971297 df.query(' a in b and c < d' )
12981298
12991299 # pure Python
1300- df[df.b .isin(df.a ) & (df.c < df.d )]
1300+ df[df[ ' b ' ] .isin(df[ ' a ' ] ) & (df[ ' c ' ] < df[ ' d ' ] )]
13011301
13021302
13031303 .. note ::
@@ -1326,7 +1326,7 @@ to ``in``/``not in``.
13261326 df.query(' b == ["a", "b", "c"]' )
13271327
13281328 # pure Python
1329- df[df.b .isin([" a" , " b" , " c" ])]
1329+ df[df[ ' b ' ] .isin([" a" , " b" , " c" ])]
13301330
13311331 df.query(' c == [1, 2]' )
13321332
@@ -1338,7 +1338,7 @@ to ``in``/``not in``.
13381338 df.query(' [1, 2] not in c' )
13391339
13401340 # pure Python
1341- df[df.c .isin([1 , 2 ])]
1341+ df[df[ ' c ' ] .isin([1 , 2 ])]
13421342
13431343
13441344 Boolean operators
@@ -1352,7 +1352,7 @@ You can negate boolean expressions with the word ``not`` or the ``~`` operator.
13521352 df[' bools' ] = np.random.rand(len (df)) > 0.5
13531353 df.query(' ~bools' )
13541354 df.query(' not bools' )
1355- df.query(' not bools' ) == df[~ df. bools]
1355+ df.query(' not bools' ) == df[~ df[ ' bools' ] ]
13561356
13571357 Of course, expressions can be arbitrarily complex too:
13581358
@@ -1362,7 +1362,10 @@ Of course, expressions can be arbitrarily complex too:
13621362 shorter = df.query(' a < b < c and (not bools) or bools > 2' )
13631363
13641364 # equivalent in pure Python
1365- longer = df[(df.a < df.b) & (df.b < df.c) & (~ df.bools) | (df.bools > 2 )]
1365+ longer = df[(df[' a' ] < df[' b' ])
1366+ & (df[' b' ] < df[' c' ])
1367+ & (~ df[' bools' ])
1368+ | (df[' bools' ] > 2 )]
13661369
13671370 shorter
13681371 longer
@@ -1835,14 +1838,14 @@ chained indexing expression, you can set the :ref:`option <options>`
18351838
18361839 # This will show the SettingWithCopyWarning
18371840 # but the frame values will be set
1838- dfb[' c' ][dfb.a .str.startswith(' o' )] = 42
1841+ dfb[' c' ][dfb[ ' a ' ] .str.startswith(' o' )] = 42
18391842
18401843 This however is operating on a copy and will not work.
18411844
18421845::
18431846
18441847 >>> pd.set_option('mode.chained_assignment','warn')
1845- >>> dfb[dfb.a .str.startswith('o')]['c'] = 42
1848+ >>> dfb[dfb['a'] .str.startswith('o')]['c'] = 42
18461849 Traceback (most recent call last)
18471850 ...
18481851 SettingWithCopyWarning:
0 commit comments