How to read CSV file with data frame with row names in Pandas

I have a CSV file ( tmp.csv ) that looks like this:

  xyz bar 0.55 0.55 0.0 foo 0.3 0.4 0.1 qux 0.0 0.3 5.55 

It was created using Pandas as follows:

  In [103]: df_dummy Out[103]: xyz bar 0.55 0.55 0.00 foo 0.30 0.40 0.10 qux 0.00 0.30 5.55 In [104]: df_dummy.to_csv("tmp.csv",sep="\t") 

What I want to do is read the CSV in the same data view. I tried this, but don't give what I want:

 In [108]: pd.io.parsers.read_csv("tmp.csv",sep="\t") Out[108]: Unnamed: 0 xyz 0 bar 0.55 0.55 0.00 1 foo 0.30 0.40 0.10 2 qux 0.00 0.30 5.55 

What is the right way to do this?

+7
python pandas
source share
1 answer

You can use the index_col parameter:

 >>> pd.io.parsers.read_csv("tmp.csv",sep="\t",index_col=0) xyz bar 0.55 0.55 0.00 foo 0.30 0.40 0.10 qux 0.00 0.30 5.55 
+9
source share

All Articles