Jun-24-2019, 12:20 AM
I want to replace all \n within pandas dataframe with space.
I tried with the following code. However, I couldn't replace \n within the list values in the columns.
1 2 3 4 |
import pandas as pd table = pd.DataFrame(data = { 'ClientID' :[ 100 , 102 , 103 ], 'Category' :[ 'A' , 'Category\nZ' ,[ 'Non\nCategory A' ,'']], 'Income' :[ 800 , 900 ,[ 1000 , 2000 ]],},) |
1 |
table = table.replace(r '\n' , ' ' , regex = True ) |
Output:Out[400]:
Category ClientID Income
0 A 100 800
1 Category Z 102 900
2 [Non\nCategory A, ] 103 [1000, 2000]
Appreciate if someone can help on this.