Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

pandas - Python - splitting sentences dataframe into multiple columns

I have sentences in csv that I'd like to split it by the delimiter of spaces.

enter image description here

I've tried using this :-

df2 = df["Text"].str.split()

but it doesnt gave out the ideal result. It shows up like this instead.

enter image description here

I am aware how to do it via power query in excel but I would like to learn how to do similar move using Python.

enter image description here

Here's the ideal result that I'd like to achieve


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

try this:

df2 = df["Text"].str.split(',', expand=True)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...