Created
October 3, 2016 07:40
-
-
Save ki-chi/5148179f14c655bf860dcf9a09923e70 to your computer and use it in GitHub Desktop.
Convert instances of jsm into Pandas DataFrame.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import jsm | |
import datetime | |
def get_historical_price(stockcode, start_date=None, end_date=None): | |
q = jsm.Quotes() | |
if start_date is None or end_date is None: | |
jsm_data = q.get_historical_prices(stockcode) | |
else: | |
jsm_data = q.get_historical_prices(stockcode, jsm.DAILY, start_date, end_date, jsm.DAILY) | |
jsm_dict = map(lambda x: x.__dict__ , jsm_data) | |
f = lambda x: pd.DataFrame.from_dict(x, orient="index").transpose().set_index("date") | |
result = pd.concat(list(map(f, jsm_dict))) | |
return result | |
def get_financial_data(stockcode): | |
q = jsm.Quotes() | |
jsm_data = q.get_finance(stockcode) | |
jsm_dict = jsm_data.__dict__ | |
f = lambda x: pd.DataFrame.from_dict(x, orient="index").transpose() | |
result = f(jsm_dict) | |
result["code"] = stockcode | |
return result.set_index("code") | |
def get_brand_data(brand_id=None): | |
q = jsm.Quotes() | |
if brand_id is None: | |
jsm_data = q.get_brand() | |
else: | |
jsm_data = q.get_brand(brand_id) | |
jsm_dict = map(lambda x: x.__dict__ , jsm_data) | |
f = lambda x: pd.DataFrame.from_dict(x, orient="index").transpose().set_index("ccode") | |
result = pd.concat(list(map(f, jsm_dict))) | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment