Working with Text Data Module
In this example Working with Text Data we are going to show you everything step for step.
Here you can add your “chicago.csv” file with pd.read_csv() Method
with .info () Method you can see how much Data Memory Usage and the values your index
The nunique() function is used to count distinct observations over requested axis.
The count() function to find the number for each column or row.
The astype() method is used to cast a pandas object to a specified dtype and function also provides the capability to convert any suitable existing column to categorical type.
Common String Methods – lower upper title and len
Example of the astype (), lower (), upper (), title () methods
The .lower() and .upper() string methods are self-explanatory. Performing the .upper() method on a string converts all of the characters to uppercase, whereas the lower() method converts all of the characters to lowercase.
The title () method returns a string where the first character in every word is upper case. Like a header, or a title.
You can use the len() to get the length of the given string, array, list, tuple, dictionary, etc.
Example of columns in Lower with .str.lower() method
In upper with .str.upper() method
In title with .str.title() method
Here example of values in title with .str.title() method
Example of values with .str.len() method
The .str.replace() Method.
The replace() method replaces a specified phrase with another specified phrase.
Example of the replace() method
Here you can see the DataFrame of NaN values
You can call the .dropna (how=”all”) and remove missing values.
Filtering with String Methods
The str.contains () function is used to test if pattern or regex is contained within a string of a Series or Index.
Here example on the word “water” with str.contains () and str.lower () methods
You see here the word “water”, has become “True”
with [mask] you can see the word “water” in your index in beginning and in middle of the table
Call str.startswith if you want the word “water” only at the beginning of the word
Call str.endswith if you want the word “ist” only at the end of the word
strip lstrip and rstrip Methods
Example of the lstrip() rstrip() strip () methods
The lstrip() (left strip) function removes leading whitespace (on the left) in the string.
The rstrip() (right strip) function removes the trailing whitespace (on the right).
The strip() function removes both leading and trailing whitespace.
Working with Text Data Module .Split Strings by Characters with .str.split()
Example of the .str.split() Method
The function splits () the string in the Series/Index from the beginning, at the specified delimiter string.
Example of the .str.split() and str.get() Methods
The str.get() function is used to extract element from each component at specified position.
Example of the .str.split(), str.get(), value_counts() Methods
The value_counts() function is used to get a Series containing counts of unique values and the first element is the most frequently-occurring element. ImageImage
About Fellow Consulting
Fellow Consulting AG, based in Poing near Munich, has been advising clients on digitizing their business processes for more than 10 years.
We know how our customers can implement their digital vision. Together with our partners infor_ Amazon AWS, Microsoft Azure, SugarCRM, and Ephesoft, we bring the mission of digitalization to life.
We act as an operational and strategic specialist for our clients as well as a sparring partner for the everyday challenges of digital transformation.