【发布时间】:2017-07-30 07:44:42
【问题描述】:
我已阅读有关此主题的几个问题,但似乎没有什么对我有用。
我想从该页面“http://archive.ics.uci.edu/ml/machine-learning-databases/statlog/heart/heart.dat”检索具有特定列名称的数据。
我的代码如下,它不允许我为数据的列分配名称,因为所有内容都在一个列中:
import pandas as pd
import io
import requests
url="http://archive.ics.uci.edu/ml/machine-learningdatabases/statlog/heart/heart.dat"
s=requests.get(url).content
header_row = ['age','sex','chestpain','restBP','chol','sugar','ecg','maxhr','angina','dep','exercise','fluor','thal','diagnosis']
c=pd.read_csv(io.StringIO(s.decode('utf-8')), names=header_row)
print(c)
输出是:
age sex chestpain \
0 70.0 1.0 4.0 130.0 322.0 0.0 2.0 109.0 0.0 2.4... NaN NaN
1 67.0 0.0 3.0 115.0 564.0 0.0 2.0 160.0 0.0 1.6... NaN NaN
2 57.0 1.0 2.0 124.0 261.0 0.0 0.0 141.0 0.0 0.3... NaN NaN
3 64.0 1.0 4.0 128.0 263.0 0.0 0.0 105.0 1.0 0.2... NaN NaN
我必须做什么才能实现我的目标?
非常感谢!!!
【问题讨论】:
-
您确定该网址吗?打开时出现 404 错误