Reputation: 73
I have an excel sheet which has a column as remarks. So, for example, a cell contains data in a format like
- There is a book.
- There is also a pen along with the book.
- So, I decided to study for a while.
When I convert that excel into a pandas data frame, the data frame only captures the 1st point till the new line. It won't capture point no 2. So, How can I get all points in an excel to one cell of a data frame?
The data which I get looks like:
- There is a book.
The data which I want should look like:
- There is a book. 2. There is also a pen along with the book. 3. So, I decided to study for a while.
Upvotes: 0
Views: 38
Reputation: 615
I created an excel file with a column named remarks which looks like below:
remarks
0 1. There is a book.
2. There is also a pen along with the book.
3. So, I decided to study for a while.
Here, I have entered all the text mentioned in your question into single cell.
import pandas as pd
df = pd.read_excel('remarks.xlsx')
Now when I try to print the column remarks it gives:
df['remarks']
0 1. There is a book.\n2. There is also a pen al...
Name: A, dtype: object
To solve your problem try:
df['remarks_without_linebreak'] = df['remarks'].replace('\n',' ', regex=True)
If you print the row in the column 'remarks_without_linebreak' you will get the result as you want
Upvotes: 1