Page 1 of 1

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

Posted: Mon Jun 06, 2022 6:13 pm
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 19 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