Python. String manipulation in data frame column. A data frame contains 2 columns: ■ Name: Name of student ■ description

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Python. String manipulation in data frame column. A data frame contains 2 columns: ■ Name: Name of student ■ description

Post by answerhappygod »

Python String Manipulation In Data Frame Column A Data Frame Contains 2 Columns Name Name Of Student Description 1
Python String Manipulation In Data Frame Column A Data Frame Contains 2 Columns Name Name Of Student Description 1 (147.31 KiB) Viewed 17 times
Python. String manipulation in data frame
column.
name_data = ["Tom", "Nick", "Jack", "Tim"]
info_data = ["Hello. My name is Tom",
"Hi.I am nick and I am
twelve.",
"Hi. I'm Jack.I have 3
dogs",
"I'm Tim.I am 1.24 meters
tall.I dislike cats"]
data = {"Name": name_data, "description": info_data }
df = pd.DataFrame(data)
df
Python. String manipulation in data frame column. A data frame contains 2 columns: ■ Name: Name of student ■ description: A few sentences about the student import pandas as pd. name_data = ["Tom", "Nick", "Jack", "Tim"] info_data = ["Hello. My name is Tom", "Hi.I am nick and I am twelve.", "Hi. I'm Jack. I have 3 dogs", "I'm Tim. I am 1.24 meters tall. I dislike cats"] data = {"Name": name_data, "description": info_data } df = pd.DataFrame (data) df Name description 0 Tom Hello. My name is Tom 1 Nick Hi.I am nick and I am twelve. 2 Jack Hi. I'm Jack. I have 3 dogs 3 Tim I'm Tim.I am 1.24 meters tall.I dislike cats Problem: For certain sentences, there is no space after a full stop (eg. "I'm Jack.I have 3 dogs"). Task: Using python and with any libraries, change the text within the column such that a space is added after a full stop – BUT: ▪ ONLY if the space was not already present ▪ AND either side of the full stop are not digits (so "1.24 meters" is not affected). Expected Output: Name description 0 Tom Hello. My name is Tom 1 Nick Hi. I am nick and I am twelve. 2 Jack Hi. I'm Jack. I have 3 dogs 3 Tim I'm Tim. I am 1.24 meters tall. I dislike cats
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply