Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

>Solution :

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’])

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading