Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python pandas csv exporting

I've problem exporting a dataframe to CSV file.

Data types are String and Float64 values like this:

In [19]: segmenti_t0
Out[19]:
SEGM1  SEGM2
AD     P.S.         8.3
       SCREMATO     0.6
CRE    STD          1.2
FUN    INTERO       0.0
       P.S.         2.0
       SCREMATO     0.0
NORM   INTERO      13.1
       P.S.        69.5
       SCREMATO     5.2
Name: Quota volume_t0

I try to export this dataframe with this command:

IN [20]: segmenti_t0.to_csv('C:Users\MarioRossi\prova.csv', sep=";")

When I try to open it with Excel or I try to import it in excel from the csv file with formatting parameters I obtain really strange formatting for float values like 69.5000 or 5.2.0000000 or date times formatting too like this:

NORM    INTERO  13.01
NORM    P.S.    69.05.00
NORM    SCREMATO    5.02

Consider that I m using European format ("," as decimal as I use to import the original raw data from csv files).

Please help me: I developed a software (with GUI and so on) and I cant deliver it for that reason!

Thanks

like image 455
Manuel Zompetta Avatar asked Jan 08 '13 14:01

Manuel Zompetta


1 Answers

You should use the to_excel DataFrame method:

# first convert Series to DataFrame
df_segmenti_t0 = DataFrame(segmenti_t0)

# save as excel spreadsheet
df_segmenti_t0.to_excel('prova.xls')
like image 188
Andy Hayden Avatar answered Nov 03 '22 13:11

Andy Hayden