1

I have a Dataframe as below that has 3 columns namely id, name and feedback. One of the values for customer_input has a value as below

id,name,feedback
201,Robert,"response time is slow
"

I am having issues working inserting this data into a DB table due to the long text it hold in the feedback column. The entire text within quotes is value for one cell. How could I remove all the extra spaces between the word slow and the closing quotes (") in the next line Could anyone advice how I could work with this data.

I am working with Amazon Redshift table

Kevin Nash
  • 1,511
  • 3
  • 18
  • 37

2 Answers2

1

you can use simple str.replace

df['feedback'] = df['feedback'].str.replace('\r','')

df['feedback'] = df['feedback'].str.replace('\n','')
print(df)
201  Robert  response time is slow
user96564
  • 1,578
  • 5
  • 24
  • 42
0

To remove spaces everywhere, you could do it something like below in Python pandas.

df.columns = df.columns.str.replace(' ', '')

Refer following links for more details on various permutation combination.

https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html#pandas.DataFrame.replace

Removing space from dataframe columns in pandas

Red Boy
  • 5,429
  • 3
  • 28
  • 41