这条线不见了
net_income = IS[0]['netIncome']
这就是为什么“我想用最后一行实现的目标不清楚”的问题。因此整个代码是:
net_income = IS[0]['netIncome']
BS = requests.get(f'https://financialmodelingprep.com/api/v3/balance-sheet-statement/{company}?apikey={demo}').json()
# get income statement as % of revenue for future predictions and forecast 5 next IS years
income_statement = pd.DataFrame.from_dict(IS[0], orient='index')
income_statement = income_statement[5:26]
income_statement.columns = ['current_year']
income_statement['as_%_of_revenue'] = income_statement /income_statement.iloc[0]
我想要实现的是将收入报表除以收入(销售额)= 收入/收入(均为当年)。结果将给我一个预测未来几年的收入百分比,它是一个乘数。
分割前的数据是这样的。
问题是income_statement被定义为一个类,因为dataframe
<class 'pandas.core.frame.DataFrame'>
current_year
period FY
revenue 495308000
costOfRevenue 43839000
grossProfit 451469000
grossProfitRatio 0.911491
researchAndDevelopmentExpenses 101117000
generalAndAdministrativeExpenses 101439000
sellingAndMarketingExpenses 252820000
otherExpenses 0
operatingExpenses 455376000
costAndExpenses 499215000
interestExpense 38119000
depreciationAndAmortization 12101000
ebitda 8.194e+06
ebitdaratio 0.0165432
operatingIncome -3.907e+06
operatingIncomeRatio -0.00788802
totalOtherIncomeExpensesNet 14382000
incomeBeforeTax -27645000
incomeBeforeTaxRatio -0.0558138
incomeTaxExpense 0
我是 python 的新手(3 个月),所以我什至不确定所有简单的问题..我猜
感谢您的帮助
更新
我现在就是这样做的(甚至会花费我更多的时间)
我也申报了收入
net_income = IS[0]['netIncome']
revenue = IS[0]["revenue"]
并像这样计算
income_statement['as_%_of_revenue'] = (net_income/revenue)*100
期待这是否会导致任何进一步的问题,我猜
数据现在看起来像这样
current_year as_%_of_revenue
period FY -4.920978
revenue 495308000 -4.920978
costOfRevenue 43839000 -4.920978
grossProfit 451469000 -4.920978
grossProfitRatio 0.911491 -4.920978
researchAndDevelopmentExpenses 101117000 -4.920978
generalAndAdministrativeExpenses 101439000 -4.920978
sellingAndMarketingExpenses 252820000 -4.920978
otherExpenses 0 -4.920978
operatingExpenses 455376000 -4.920978
costAndExpenses 499215000 -4.920978
interestExpense 38119000 -4.920978
depreciationAndAmortization 12101000 -4.920978
ebitda 8.194e+06 -4.920978
ebitdaratio 0.0165432 -4.920978
operatingIncome -3.907e+06 -4.920978
operatingIncomeRatio -0.00788802 -4.920978
totalOtherIncomeExpensesNet 14382000 -4.920978
incomeBeforeTax -27645000 -4.920978
incomeBeforeTaxRatio -0.0558138 -4.920978
incomeTaxExpense 0 -4.920978
netIncome -24374000 -4.920978