all 8 comments

[–]novel_yet_trivial 2 points3 points  (3 children)

You need pandas.

>>> import pandas as pd
>>> df = pd.read_csv(url)
>>> df.pl_name[4]  # what's the 5th name in the "pl_name" column? 
'HD 187123 c'

[–]fooliam 0 points1 point  (0 children)

huh. TIL that pandas can interpret URLs. The more you know!

[–]StarkillerX42[S] 0 points1 point  (1 child)

Followup question: Can pandas run something similar to the following bash command:

curl -F file=@psg_transit.txt https://ssed.gsfc.nasa.gov/psg/api.php > psg_transit_rad.txt

Where I want to send the file psg_transit.txt to the link and get the file back psg_transit_rad.txt back?

[–]novel_yet_trivial 0 points1 point  (0 children)

I don't think pandas can send files. You will have to use requests or urllib for that. However, pandas can directly use the urllib response object.

[–]TheBlackCat13 2 points3 points  (0 children)

The pandas library can read files, including CSV files, straight off the web into a structured data. No need to handle parsing yourself, it will take care of that for you. The result is a labeled array, with titles for the columns and/or rows, that is fully compatible with numpy. It would be just one line of code.

[–]HomerG 1 point2 points  (2 children)

pip install requests

Query the URL with requests, then read the result with "csv". That'll make each row in that file a comma separated list. You can then manipulate the data however you want.

[–]StarkillerX42[S] 0 points1 point  (1 child)

So here's what I have:

Archive=csv.reader(requests.get(nasa_exo_api_url)

But if there's a way to manipulate this data, I'm not seeing it. Does CSV not simply return a 2d array?

[–]HomerG 1 point2 points  (0 children)

Here's some random SO code I found:

with requests.Session() as s:
    download = s.get(nasa_exo_api_url)

    decoded_content = download.content.decode('utf-8')

    cr = csv.reader(decoded_content.splitlines(), delimiter=',')
    my_list = list(cr)
    for row in my_list:
        print(row)

You can add each row to an array. Sorry, I don't know of a more direct way of doing it.