Answers for "pandas length of string column"

3

make length string in pandas

df['name_length'] = df.Name.str.len() 

// or 

df['name_length'] = df.Name.apply(len)
Posted by: Guest on June-16-2020
0

pandas apply check for string length in column

#The *mask* variable is a dataframe of booleans, giving you True or False for the selected condition
mask = df[['A','B']].applymap(lambda x: len(str(x)) == 10)

#Here you can just use the mask to filter your rows, using the method *.all()* to filter only rows that are all True, but you could also use the *.any()* method for other needs
df = df[mask.all(axis=1)]
Posted by: Guest on October-07-2021

Code answers related to "pandas length of string column"

Python Answers by Framework

Browse Popular Code Answers by Language