2015-01-07 12 views
7

Ich habe eine CSV-Datei (tmp.csv), die wie folgt aussieht:Wie CSV lesen

 x  y  z 
bar  0.55 0.55 0.0 
foo  0.3  0.4  0.1 
qux  0.0  0.3  5.55 

Es wurde mit Pandas auf diese Weise erstellt:

In [103]: df_dummy 
    Out[103]: 
      x  y  z 
    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") 

Was ich tun möchte, ist diese CSV in die gleiche Datendarstellung zu lesen. Ich habe versucht, dies aber nicht geben, was ich will:

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

Was ist der richtige Weg, es zu tun?

Antwort

9

können Sie index_col Parameter verwenden:

>>> pd.io.parsers.read_csv("tmp.csv",sep="\t",index_col=0) 
     x  y  z 
bar 0.55 0.55 0.00 
foo 0.30 0.40 0.10 
qux 0.00 0.30 5.55