Using pandas, I exported to a csv file a data framework whose cells contain tuples of strings. The resulting file has the following structure:
index,colA
1,"('a','b')"
2,"('c','d')"
Now I want to read it using read_csv. However, no matter what I try, pandas interprets the values as strings, not tuples. For instance:
In []: import pandas as pd
df = pd.read_csv('test',index_col='index',dtype={'colA':tuple})
df.loc[1,'colA']
Out[]: "('a','b')"
Is there a way to tell pandas to do the right thing? Preferably without heavy post-processing of the data frame: the actual table has 5,000 rows and 2,500 columns.
source
share