Guest User

Untitled

a guest
Nov 18th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.08 KB | None | 0 0
  1. a = Statements("AAPL","income_statement", "FY", ["2017","2018"])
  2. d = a.get()
  3. print(d)
  4.  
  5. [{'tag': 'operatingrevenue', 'value': 229234000000.0}, {'tag': 'totalrevenue', 'value': 229234000000.0}, {'tag': 'operatingcostofrevenue', 'value': 141048000000.0}, {'tag': 'totalcostofrevenue', 'value': 141048000000.0}, {'tag': 'totalgrossprofit', 'value': 88186000000.0}, {'tag': 'sgaexpense', 'value': 15261000000.0}, {'tag': 'rdexpense', 'value': 11581000000.0}, {'tag': 'totaloperatingexpenses', 'value': 26842000000.0}, {'tag': 'totaloperatingincome', 'value': 61344000000.0}, {'tag': 'otherincome', 'value': 2745000000.0}, {'tag': 'totalotherincome', 'value': 2745000000.0}, {'tag': 'totalpretaxincome', 'value': 64089000000.0}, {'tag': 'incometaxexpense', 'value': 15738000000.0}, {'tag': 'netincomecontinuing', 'value': 48351000000.0}, {'tag': 'netincome', 'value': 48351000000.0}, {'tag': 'netincometocommon', 'value': 48351000000.0}, {'tag': 'weightedavebasicsharesos', 'value': 5217242000.0}, {'tag': 'basiceps', 'value': 9.27}, {'tag': 'weightedavedilutedsharesos', 'value': 5251692000.0}, {'tag': 'dilutedeps', 'value': 9.21}, {'tag': 'weightedavebasicdilutedsharesos', 'value': 5215900000.0}, {'tag': 'basicdilutedeps', 'value': 9.27}, {'tag': 'cashdividendspershare', 'value': 2.4}]
  6. {'ticker': 'AAPL', 'statement': 'income_statement', 'type': 'FY', 'fiscal_year': '2017'}
  7. [{'tag': 'operatingrevenue', 'value': 265595000000.0}, {'tag': 'totalrevenue', 'value': 265595000000.0}, {'tag': 'operatingcostofrevenue', 'value': 163756000000.0}, {'tag': 'totalcostofrevenue', 'value': 163756000000.0}, {'tag': 'totalgrossprofit', 'value': 101839000000.0}, {'tag': 'sgaexpense', 'value': 16705000000.0}, {'tag': 'rdexpense', 'value': 14236000000.0}, {'tag': 'totaloperatingexpenses', 'value': 30941000000.0}, {'tag': 'totaloperatingincome', 'value': 70898000000.0}, {'tag': 'otherincome', 'value': 2005000000.0}, {'tag': 'totalotherincome', 'value': 2005000000.0}, {'tag': 'totalpretaxincome', 'value': 72903000000.0}, {'tag': 'incometaxexpense', 'value': 13372000000.0}, {'tag': 'netincomecontinuing', 'value': 59531000000.0}, {'tag': 'netincome', 'value': 59531000000.0}, {'tag': 'netincometocommon', 'value': 59531000000.0}, {'tag': 'weightedavebasicsharesos', 'value': 4955377000.0}, {'tag': 'basiceps', 'value': 12.01}, {'tag': 'weightedavedilutedsharesos', 'value': 5000109000.0}, {'tag': 'dilutedeps', 'value': 11.91}, {'tag': 'weightedavebasicdilutedsharesos', 'value': 4956800000.0}, {'tag': 'basicdilutedeps', 'value': 12.01}, {'tag': 'cashdividendspershare', 'value': 2.72}]
  8. {'ticker': 'AAPL', 'statement': 'income_statement', 'type': 'FY', 'fiscal_year': '2018'}
  9.  
  10. ticker = "MMM"
  11. __________
  12. Class ***:
  13. class code
  14. __________
  15.  
  16. e= Statements(ticker,"income_statement","FY", ["2017", "2018"])
  17. f = e.get()
  18. print(e)
  19.  
  20. {'ticker': 'MMM', 'statement': 'income_statement', 'type': 'FY', 'fiscal_year': '2017'}
  21. Traceback (most recent call last):
  22. []
  23. File "C:/Users/ruleb/Desktop/python test/Ptf_Project/Financials.py", line 96, in <module>
  24. {'ticker': 'MMM', 'statement': 'income_statement', 'type': 'FY', 'fiscal_year': '2018'}
  25. f = e.get()
  26. File "C:/Users/ruleb/Desktop/python test/Ptf_Project/Financials.py", line 86, in get
  27. df = df.applymap(lambda x: x["value"])
  28. File "C:UsersrulebAppDataLocalProgramsPythonPython37-32libsite-packagespandascoreframe.py", line 6072, in applymap
  29. return self.apply(infer)
  30. File "C:UsersrulebAppDataLocalProgramsPythonPython37-32libsite-packagespandascoreframe.py", line 6014, in apply
  31. return op.get_result()
  32. File "C:UsersrulebAppDataLocalProgramsPythonPython37-32libsite-packagespandascoreapply.py", line 318, in get_result
  33. return super(FrameRowApply, self).get_result()
  34. File "C:UsersrulebAppDataLocalProgramsPythonPython37-32libsite-packagespandascoreapply.py", line 142, in get_result
  35. return self.apply_standard()
  36. File "C:UsersrulebAppDataLocalProgramsPythonPython37-32libsite-packagespandascoreapply.py", line 248, in apply_standard
  37. self.apply_series_generator()
  38. File "C:UsersrulebAppDataLocalProgramsPythonPython37-32libsite-packagespandascoreapply.py", line 277, in apply_series_generator
  39. results[i] = self.f(v)
  40. File "C:UsersrulebAppDataLocalProgramsPythonPython37-32libsite-packagespandascoreframe.py", line 6070, in infer
  41. return lib.map_infer(x.astype(object).values, func)
  42. File "pandas/_libs/srcinference.pyx", line 1472, in pandas._libs.lib.map_infer
  43. File "C:/Users/ruleb/Desktop/python test/Ptf_Project/Financials.py", line 86, in <lambda>
  44. df = df.applymap(lambda x: x["value"])
  45. TypeError: ("'NoneType' object is not subscriptable", 'occurred at index operatingrevenue')
  46.  
  47. Process finished with exit code 1
  48.  
  49. import requests
  50. import pandas as pd
  51. ticker = "MMM"
  52.  
  53. class Statements:
  54.  
  55. def __init__(self,ticker = "AAPL",statement= "income_statement",period= "FY",fiscal_year = ["2017","2018"]):
  56. self.ticker = ticker
  57. self.statement = statement
  58. self.period = period
  59. self.fiscal_year = fiscal_year
  60.  
  61. # , ticker, statement, period, fiscal_year
  62. def get(self):
  63. api_username = 'x'
  64. api_password = 'x'
  65. base_url = "https://api.intrinio.com"
  66. s = []
  67. for year in self.fiscal_year:
  68. request_url = base_url + "/financials/standardized"
  69.  
  70. query_params = {
  71. 'ticker': self.ticker,
  72. 'statement': self.statement,
  73. 'type': self.period,
  74. 'fiscal_year': year
  75. }
  76.  
  77. response = requests.get(request_url, params=query_params, auth=(api_username, api_password))
  78. if response.status_code == 401: print("Unauthorized! Check your username and password."); exit()
  79. data = response.json()["data"]
  80. s.append(data)
  81. print(data)
  82. print(query_params)
  83.  
  84. df = pd.DataFrame(s, index = self.fiscal_year)
  85. df.columns = [i["tag"] for i in df.iloc[0].values]
  86. df = df.applymap(lambda x: x["value"])
  87. # print(df)
  88. return df
  89.  
  90.  
  91. a = Statements("AAPL","income_statement", "FY", ["2017","2018"])
  92. d = a.get()
  93. print(d)
  94.  
  95. e= Statements(ticker,"income_statement","FY", ["2017", "2018"])
  96. f = e.get()
  97. print(f)
Add Comment
Please, Sign In to add comment