'Unique pandas dataframe issue. I want to remove the newline but "/n" exist within the entry

As said above, I want to fix the following text output from this:

Incorrect Print of Table

to this:

Correct Print of Table

Though the pandas list can be indexed properly, the print output is essential to the code that I am writing.

Or from this:

             0                 1
0  Application          Password
1       Amazon  3H@)G<1!*ly[go><
2         Hulu  >&c3HX
                      \074Iq<VW
3      YouTube  ~NR\ng
                      X.VkAjqVa

To this:

         0                 1
1   Amazon  3H@)G<1!*ly[go><
2     Hulu  >&c3HX\074Iq<VW
3  YouTube  ~NR\ngX.VkAjqVa

The values are being read in from a csv, and converted to a dataframe.

Cant remove any instance of "\n" as the strings are generated randomly and the option of having a "\" and "n" next to each other cannot be removed.

All I am doing is this to print the dataframe:

print(table)

What I have tried:

table = table.replace(r'\\n',' ', regex=True)

Also tried this:

print(table.to_string())

Result:

             0                 1
0  Application          Password
1       Amazon  3H@)G<1!*ly[go><
2         Hulu  >&c3HX
                      \074Iq<VW
3      YouTube   ~NR g
                      X.VkAjqVa

Any tips on how to remediate this issue?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source