简体   繁体   中英

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

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM