python - Pandas - pd.read_html, Problems reading negative values -
i trying convert table pandas dataframe. problem here pandas not recognize negative values in table.
import pandas pd url = 'http://www.scb.se/en_/finding-statistics/statistics-by-subject-area/prices-and-consumption/consumer-price-index/consumer-price-index-cpi/aktuell-pong/33779/consumer-price-index-cpi/287612/' df = pd.read_html(url,index_col='year',header=0,parse_dates=true)[0] print(df) any suggestions how can proceed?
thank in advance
that table using different hyphen character rather ascii minus. replace , re-convert floats.
in [64]: df.iloc[0,0] out[64]: u'\u20111.1' in [65]: column in df: ...: if df[column].dtype == np.object_: ...: df[column] = df[column].str.replace(u'\u2011', '-').astype(float) in [66]: df.iloc[0,0] out[66]: -1.1000000000000001
Comments
Post a Comment