'Python/Pandas adding quotes to string

I'm using Python/Pandas to edit a csv file created by another program.

One of the columns contains values contained within duoble quotes:

"RGB(0,255,255)"

for example. This is just how it is output by the program and I need to preserve these quotes in order for it to be read back into the program once I have edited it. Currently when I try to exporting the edited data frame to a .csv, the quotes around the values dissapear. so the values look like this:

RGB(0,255,255)

I tried adding quotes manually to the values in the column before exporting, but now the .csv file has triple quotes so looks like this:

"""RGB(0,255,255)"""

I'm not doing anything with this particular column, I literally just need it to retain the format it had before being read into my Python script. I'm assuiming there are some arguments in either my read_csv or to_csv commands but I'm not sure where to start. Any help gratefully appreciated!



Solution 1:[1]

Save the DataFrame as a pickle instead.

df.to_pickle('test.pkl')

# To load the dataframe again
df = pd.read_pickle('test.pkl')

This will preserve the structures!

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 William Rosenbaum