Tuesday, August 21, 2018

Download csv into DataFrame



import urllib
import urllib2
import csv
import pandas

#Calling this function will download a csv and return it in a dataframe
#21 AUG 2018
#David Tsang

def downloadasdataframe(url):

    req = urllib2.Request(url)
    response = urllib2.urlopen(req)
    reader = csv.reader(response)
    ls_data = list(reader)
    headers = ls_data[0]
    df_data = pandas.DataFrame.from_records(ls_data[1:], columns=headers)
    return df_data

No comments:

Post a Comment

Applying SMA10/20, SMA20/50 as trading signals

This is the comparison for results before and after applying SMA10/20 and SMA20/50 in the stock trader. Background Trading 3 stock ma...