@@ -380,7 +380,7 @@ Python determines the length of a character string with the ``len`` function.
380
380
``len `` includes trailing blanks. Use ``len `` and ``rstrip `` to exclude
381
381
trailing blanks.
382
382
383
- .. code-block :: none
383
+ .. ipython :: python
384
384
385
385
tips[' time' ].str.len()
386
386
tips[' time' ].str.rstrip().str.len()
@@ -407,7 +407,7 @@ substring. If the substring is found, the function returns its
407
407
position. Keep in mind that Python indexes are zero-based and
408
408
the function will return -1 if it fails to find the substring.
409
409
410
- .. code-block :: none
410
+ .. ipython :: python
411
411
412
412
tips[' sex' ].str.find(" ALE" )
413
413
@@ -429,7 +429,7 @@ In Python, you can use ``[]`` notation to extract a substring
429
429
from a string by position locations. Keep in mind that Python
430
430
indexes are zero-based.
431
431
432
- .. code-block :: none
432
+ .. ipython :: python
433
433
434
434
tips[' sex' ].str[0 :1 ]
435
435
@@ -457,7 +457,7 @@ Python extracts a substring from a string based on its text
457
457
by using regular expressions. There are much more powerful
458
458
approaches, but this just shows a simple approach.
459
459
460
- .. code-block :: none
460
+ .. ipython :: python
461
461
462
462
firstlast = pd.DataFrame({' String' : [' John Smith' , ' Jane Cook' ]})
463
463
firstlast[' First_Name' ] = firstlast[' String' ].str.split(" " , expand = True )[0 ]
@@ -485,7 +485,7 @@ the case of the argument.
485
485
486
486
The equivalent Python functions are ``upper ``, ``lower ``, and ``title ``.
487
487
488
- .. code-block :: none
488
+ .. ipython :: python
489
489
490
490
firstlast = pd.DataFrame({' String' : [' John Smith' , ' Jane Cook' ]})
491
491
firstlast[' string_up' ] = firstlast[' String' ].str.upper()
0 commit comments