Python Pandas-pd.read_html,读取负值时出现问题
我正在尝试将此表转换为数据帧。我这里的问题是熊猫无法识别表中的负值Python Pandas-pd.read_html,读取负值时出现问题,python,pandas,Python,Pandas,我正在尝试将此表转换为数据帧。我这里的问题是熊猫无法识别表中的负值 import pandas as 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/
import pandas as 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)
有什么建议我可以继续吗
提前感谢您该表使用的是不同的而不是ASCII减号。您可以这样做来替换并重新转换为浮动
In [64]: df.iloc[0,0]
Out[64]: u'\u20111.1'
In [65]: for 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
我不知道你说的“识别负值”是什么意思?。当我运行你的代码时,我在输出中得到了正值和负值。现在效果很好!