简体   繁体   English

如何将数据从url导入到pandas dataframe?

[英]How to import data from a url to pandas dataframe?

I'm trying to import data from the following url into pandas dataframe:我正在尝试将数据从以下 url 导入到 pandas dataframe:

https://www.asx.com.au/data/shortsell.txt https://www.asx.com.au/data/shortsell.txt

I tried the following:我尝试了以下内容:

url = 'https://www.asx.com.au/data/shortsell.txt'
reader = pd.read_table(url, sep='\t',
                     skiprows=lambda x: x in [0, 1, 2, 3, 4, 5, 6, 7], header=None, names=[
                         'ASX', 'Company Name', 'Product/', 'Reported Gross', 'Issued', '% of issued capital'])

I expected to get data in a dataframe for each of the columns.我希望为每一列获取 dataframe 中的数据。 However, all my data is falling under 'ASX'.但是,我所有的数据都属于“ASX”。 I have re-read the python doc for read_table but don't know where I'm going wrong.我已经重新阅读了 python 文档中的 read_table 但不知道哪里出错了。

try pd.read_fwf()试试 pd.read_fwf()

ie reader = pd.read_fwf(url, sep='\t', skiprows=8, header=None, names=[ 'ASX', 'Company Name', 'Product/', 'Reported Gross', 'Issued', '% of issued capital'])即reader = pd.read_fwf(url, sep='\t', skiprows=8, header=None, names=[ 'ASX', 'Company Name', 'Product/', 'Reported Gross', 'Issued', '已发行资本的百分比'])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM