About this question
How to get the length of the dataframe string kept in each cell. Which code must be used?
How to get the length of the dataframe string kept in each cell. Which code must be used?
Log in to share your answer and help other learners.
Log in to answerBest Answer · By JanBask Python Expert
Answered on Jul 27, 2023
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: int64The 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.
Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.
Most-read guides across JanBask
Common Python interview questions, answered
Guides, tips and career advice on Python from JanBask experts.
Python How to Become a Python Developer: A Step-by-Step Guide for Beginners
Discover how to become a Python Developer via a practical 7-step guide build projects, maintain clean code, practice daily, and…
Python PCEP Certification Guide: Entry-Level Python Programmer Certification
Explore this PCEP certification guide for insights on cost, exam format, passing score, application, training, and study tips.…
Python Top 50+ Python Projects ideas for Beginners to Advanced
Discover innovative Python project ideas, explore advanced Python projects, and find good Python projects for beginners and…
Python How To Comment Out Multiple Lines In Python Like A Pro
Commenting out code is a common practice among programmers. It allows you to temporarily disable parts of your code without…