PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, August 28, 2022

[FIXED] How can I avoid python converting big numbers to scientific notation?

 August 28, 2022     csv, python     No comments   

Issue

I have data structured as follows:

['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']

I want to write this data to a csv file, but when I do, python converts the numbers to scientific notation (e.g 1.404E12).

I am using the following function to convert the list of lists to a 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)

How can I avoid this?


Solution

By using the format specification mini language described here:

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

Search for: 7.1.3.1. Format Specification Mini-Language



Answered By - Jacques de Hooge
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing