How to import data from a url to pandas dataframe?

Question:

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.

Asked By: Rhombus

||

Answers:

try pd.read_fwf()

i.e. reader = pd.read_fwf(url, sep=’t’,
skiprows=8, header=None, names=[
‘ASX’, ‘Company Name’, ‘Product/’, ‘Reported Gross’, ‘Issued’, ‘% of issued capital’])

Answered By: user1726633
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.