Discovering Data
  • Home
  • Blog
  • become_a_data_scientist
  • Code-examples

Importing numbers with commas via pandas.read_csv

1/22/2017

0 Comments

 
If you have a csv file with numbers of the form: 8,971 when you import these they will be imported as strings due to the comma. If you then try to plot your dataframe you may find you get an error: ....no numeric data to plot ..... It is possible to work around this problem in a few ways, one involves the thousands parameter to read_csv. This will get rid of the comma but the data may still be strings. You can however use the df.astype('float') command to convert to float type. You can also specify a column to convert - df['column name'],astype('float'). 

Example code:

    

0 Comments



Leave a Reply.

    This blog includes:

    Scripts mainly in Python with a few in R covering NLP, Pandas, Matplotlib and others. See the home page for links to some of the scripts.  Also includes some explanations of basic data science terminology.

    Archives

    October 2018
    June 2018
    April 2018
    June 2017
    April 2017
    March 2017
    February 2017
    January 2017
    November 2016
    September 2016
    July 2016
    June 2016
    May 2016
    December 2015
    November 2015
    April 2015
    December 2014
    November 2014

    RSS Feed

Proudly powered by Weebly
  • Home
  • Blog
  • become_a_data_scientist
  • Code-examples