Created
October 22, 2018 17:32
-
-
Save gaurav-gogia/86240590acf89ab26f167c6d6d957297 to your computer and use it in GitHub Desktop.
Trying to trim space in a csv file. Getting this exception: ValueError: could not convert string to float: '-\xa01.38'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
from patsy import dmatrix | |
from sklearn.ensemble import RandomForestClassifier | |
from sklearn import linear_model | |
%matplotlib inline | |
ipos = pd.read_csv('./scoop.csv') | |
ipos | |
ipos = ipos.applymap(lambda x: x if not '$' in str(x) else x.replace('$', '')) | |
ipos = ipos.applymap(lambda x: x if not '%' in str(x) else x.replace('%', '')) | |
ipos = ipos.applymap(lambda x: x if not 'US' in str(x) else x.replace('US', '')) | |
ipos = ipos.applymap(lambda x: x if not '- ' in str(x) else x.replace(' ', '')) | |
ipos | |
ipos.info() | |
ipos[ipos['Date']=='11/120'] | |
ipos.loc[1313, 'Date'] = '11/20/2012' | |
ipos.replace('N/C', 0, inplace=True) | |
ipos['Date'] = pd.to_datetime(ipos['Date']) | |
ipos['Offer Price'] = ipos['Offer Price'].astype('float') | |
ipos['Opening Price'] = ipos['Opening Price'].astype('float') | |
ipos['1st Day Close'] = ipos['1st Day Close'].astype('float') | |
ipos['1st Day% Px Chng'] = ipos['1st Day% Px Chng'].astype('float') | |
#ipos['$ Change Opening'] = ipos['$ Change Opening'].astype('float') Getting exceptions here | |
#ipos['$ Change Close'] = ipos['$ Change Close'].astype('float') | |
ipos['Star Ratings'] = ipos['Star Ratings'].astype('int') | |
ipos.info() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment