Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Remove \n from list of values within a pandas columns
I want to replace all \n within pandas dataframe with space.
import pandas as pd
table = pd.DataFrame(data = {'ClientID':[100,102,103],
                             'Category':['A','Category\nZ',['Non\nCategory A','']],
I tried with the following code. However, I couldn't replace \n within the list values in the columns.

table = table.replace(r'\n',  ' ', regex=True)
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.

Top Page

Messages In This Thread
Remove \n from list of values within a pandas columns - by klllmmm - Jun-24-2019, 12:20 AM

Possibly Related Threads...
Thread Author Replies Views Last Post
  access dictionary with keys from another and write values to list redminote4dd 6 138 Jun-03-2020, 05:20 PM
Last Post: DeaD_EyE
  Grabbing comma separed values from SQLite and putting them in a list PythonNPC 8 311 Apr-10-2020, 02:39 PM
Last Post: buran
  How to compare two columns and highlight the unique values of column two using pandas shubhamjainj 0 356 Feb-24-2020, 06:19 AM
Last Post: shubhamjainj
  Do Calculation between Rows based on Column values - Pandas Dataframe ahmedwaqas92 0 281 Jan-28-2020, 07:06 AM
Last Post: ahmedwaqas92
  output a list of random numbers 'x' columns wide adityavpratap 4 222 Jan-13-2020, 05:32 PM
Last Post: perfringo
  Remove all \n from end of list items JackMack118 4 12,765 Dec-27-2019, 08:34 AM
Last Post: perfringo
  Randomly assign values in List 1 to a value in List 2 Seneca260 7 787 Dec-16-2019, 12:57 PM
Last Post: BamBi25
  can't remove element from a list yokaso 6 342 Nov-06-2019, 03:11 PM
Last Post: yokaso
  How do I map a list of values to specified colors? larkypython 4 398 Nov-05-2019, 09:22 AM
Last Post: larkypython
  with input remove a string from the list konsular 3 348 Oct-12-2019, 09:25 AM
Last Post: konsular

Forum Jump:

Users browsing this thread: 1 Guest(s)