如何避免python将大数字转换为科学记数法?

时间:2015-07-09 19:29:36

标签: python csv

我的数据结构如下:

['1404407396000',
 '484745869385011200',
 '0',
 '1922149633',
 "The nurse from the university said I couldn't go if I don't get another measles immunization...",
 '-117.14384195',
 '32.8110777']

我想将此数据写入csv文件,但是当我这样做时,python会将数字转换为科学记数法(例如1.404E12)。

我使用以下函数将列表列表转换为csv:

def list_to_csv(data,name_of_csv_string):

    import csv

    """ 
    This function takes the list of lists created from the twitter data and 
    writes it to a csv.

    data - List of lists
    name_of_csv_string  -  What do you think this could be?

    """

    with open(name_of_csv_string + ".csv", "wb") as f:
        writer=csv.writer(f)      
        writer.writerows(data)

我该如何避免这种情况?

2 个答案:

答案 0 :(得分:0)

使用此处描述的格式规范迷你语言:

https://docs.python.org/2/library/string.html

搜索:7.1.3.1。格式规范迷你语言

答案 1 :(得分:0)

使用字符串格式。

writer.writerows("%f" % data)

您可以查看各种格式选项here