将SPSS数据导出为CSV时在小数点前添加零
答
似乎很难直接在SPSS中完成。 一个可能的答案:使用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')
有关“g”格式的更多信息:Format Specification Mini-Language。
并注意浮点问题(例如,请参阅answer to this question)