Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Working with Text Data

import pandas as pd
import numpy as np

s = pd.Series(['Tom', 'William Rick', 'John', 'Alber@t', np.nan, '1234','SteveSmith'])

print s
print "                                       "
print s.str.lower()
print "                                       "
print s.str.upper()
print "                                       "
print s.str.len()
print "                                       "
print "Adding String "
print s.str.cat(sep='_')



print "                                       "
print "                                       "
print "Contains match "

s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])
print s.str.contains(' ')

print "Replace "
print "                                       "
print "                                       "


print s.str.replace('@','$')


s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])

print "                                       "
print "                                       "
print ("The number of 'm's in each string:")
print s.str.count('R')
print s.str.contains('r')
print "                                       "
print "                                       "
print ("Starts with:")
print s.str.startswith('J')
print ("Starts with:")
print s.str.endswith('t')


s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])

print s.str.find('e')

# "-1" indicates that there no such pattern available in the element.


s = pd.Series(['Tom ', ' William Rick', 'John', 'Alber@t'])

print s.str.findall('e')


#Null list([ ]) indicates that there is no such pattern available in the element.

s = pd.Series(['Tom', 'William Rick', 'John', 'Alber@t'])
print s.str.swapcase()


print s.str.islower()
# to validate full string in lower 

print s.str.isupper()
# to validate full string in upper

print s.str.isnumeric()
# to validate full string in Numeric 

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.