How to get the length of the dataframe string kept in each cell. Which code must be used?

314    Asked by ajithJayaraman in Python , Asked on Jul 27, 2023

 How to get the length of the dataframe string kept in each cell. Which code must be used?

If you want to get the length of strings in the data frame, you can sue the len method on the dataframes str property. You must call the method on the certain column having the string data. Use the below-mentioned code:


Import pandas as pd
Data = pd.dataFrame({
‘ age’ : [15, 17, 20, 14, 25],
‘Name’: [“sample”, “new user”, “my name”, “jane Doe”, “John Does”]
})
data [‘name’].str.len9)

Then you will receive the result as below:

0 6
1 8
2 7
3 8
4 8
Name: name, dtype: int64

The Python online training offered at JanBask Training gives you an experience like offline classes thereby saving the students from the tiring journey to travel to the physical locations. The course provides a total Python discipline’s preparation by touching on every core concept from basic to advanced thereby making your job ready to face the tough competitive market.



Your Answer

Interviews

Parent Categories