0

Is there a way to export data from SPSS to CSV including a zero before the decimal point? Currently, I have ".41" and I would like to export "0.41" into my CSV file.

Any suggestion?

Antonin
  • 1,748
  • 7
  • 19
  • 24

1 Answers1

0

It seems difficult to do it directly in SPSS. One possible answer: using python + pandas.

import pandas as pd

def add_leading_zero_to_csv(path_to_csv_file):
    # open the file
    df_csv = pd.read_csv(path_to_csv_file)
    # you can possibly specify the format of a column if needed
    df_csv['specific_column'] = df_csv['specific_column'].map(lambda x: '%.2f' % x)
    # save the file (with a precision of 3 for all the floats)
    df_csv.to_csv(path_to_csv_file, index=False, float_format='%.3g')

More info about the "g" formatting: Format Specification Mini-Language.

And be careful with the floating point problem (e.g., see the answer to this question)

Antonin
  • 1,748
  • 7
  • 19
  • 24