@@ -380,7 +380,7 @@ Python determines the length of a character string with the ``len`` function.
380380``len `` includes trailing blanks. Use ``len `` and ``rstrip `` to exclude
381381trailing blanks.
382382
383- .. code-block :: none
383+ .. ipython :: python
384384
385385 tips[' time' ].str.len()
386386 tips[' time' ].str.rstrip().str.len()
@@ -407,7 +407,7 @@ substring. If the substring is found, the function returns its
407407position. Keep in mind that Python indexes are zero-based and
408408the function will return -1 if it fails to find the substring.
409409
410- .. code-block :: none
410+ .. ipython :: python
411411
412412 tips[' sex' ].str.find(" ALE" )
413413
@@ -429,7 +429,7 @@ In Python, you can use ``[]`` notation to extract a substring
429429from a string by position locations. Keep in mind that Python
430430indexes are zero-based.
431431
432- .. code-block :: none
432+ .. ipython :: python
433433
434434 tips[' sex' ].str[0 :1 ]
435435
@@ -457,7 +457,7 @@ Python extracts a substring from a string based on its text
457457by using regular expressions. There are much more powerful
458458approaches, but this just shows a simple approach.
459459
460- .. code-block :: none
460+ .. ipython :: python
461461
462462 firstlast = pd.DataFrame({' String' : [' John Smith' , ' Jane Cook' ]})
463463 firstlast[' First_Name' ] = firstlast[' String' ].str.split(" " , expand = True )[0 ]
@@ -485,7 +485,7 @@ the case of the argument.
485485
486486 The equivalent Python functions are ``upper ``, ``lower ``, and ``title ``.
487487
488- .. code-block :: none
488+ .. ipython :: python
489489
490490 firstlast = pd.DataFrame({' String' : [' John Smith' , ' Jane Cook' ]})
491491 firstlast[' string_up' ] = firstlast[' String' ].str.upper()
0 commit comments