我试图从coinmarketcap.com提取几个硬币的价格数据。代码如下。最近我得到错误:字节索引必须是整数或切片,而不是str。有人可以帮我理解为什么会这样吗?
有趣的是,当我只提取两三个硬币的数据时,它运行正常。但是,如果我想为更多硬币提取数据,它会开始给我这个错误信息。>>> df.groupby(['Breed','Metric'])['Age'].sum()
Breed Metric
Bernard Three month waiting 7
two month walked 2
Husky four month walked 4
three month walked 3
Sheltie One month walked 1
two month waiting 6
pig one month waiting 5
Name: Age, dtype: int64
这里是完整的错误消息:
import pandas as pd
import http.client
def get_close_px (coin):
url = 'https://coinmarketcap.com/currencies/'+str(coin)+'/historical-
data/?start=20180610&end=20180613'
try:
df = pd.read_html(url, parse_dates=[0])[0]
except (http.client.IncompleteRead) as e:
df = e.partial
df_close = df['Close**']
return df_close
coinArray = pd.concat([get_close_px ('Bitcoin'), get_close_px ('Ethereum'),
get_close_px ('Ripple'), get_close_px ('Bitcoin-Cash'),get_close_px
('Litecoin'), get_close_px ('Dash')],axis=1)
print (coinArray)
谢谢你的帮助!