简体   繁体   中英

How to import data from a url to pandas dataframe?

I'm trying to import data from the following url into pandas dataframe:

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. However, all my data is falling under 'ASX'. I have re-read the python doc for read_table but don't know where I'm going wrong.

try 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'])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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