Skip to main content

Posts

Showing posts with the label str.lower()

Python Pandas Lower/ Upper Case values in DataFrame Columns (Examples)

Lowercase / uppercase all column cell contents. String type has methods for lower-casing and upper-casing. A column is selected from dataframe and str (string) operations are made on it. But this would throw errors for int data types. We can either skip over those columns using conditionals or use "astype" assert it as a string and then operate string methods on it without any error.Based on requirement one might choose to either skip over or handle all columns with mixed type contents . Creating a new dataframe with dictionary (which has alpha numeric cell contents) # importing pandas import pandas as pd # animal_data_with_alpha_nums dictionary animal_data_with_alpha_nums = { "Name": ["Cat", "Dog", "Cow"], "Speed": [15, 12, 10], "Sound": ["Meow", "Woof", "Mooo"], "Alpha_Num":[123,"aBc123XyZ","123xYz"] } #creating a dataframe using the a...

Topics

Show more