Using pandas, I have exported to a csv file a dataframe 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 back using read_csv. However whatever I try, pandas interprets the values as strings rather than 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 of telling pandas to do the right thing? Preferably without heavy post-processing of the dataframe: the actual table has 5000 rows and 2500 columns.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…