開始使用免費開始

為 Tesla 做利潤預測

和前一個練習一樣,Tesla 的損益表資料集名為 income_statement。 運用我們在上一個練習學到的做法,現在要新增一個 2018 年的預測欄位,欄位標題設為「Forecast」。

在這個練習中,請把 filtered_income_statement 設定為只顯示 'Revenue' 這一列。

請記住,TTM 欄表示最近 12 個月的數值,會用來作為 2018 年的預測依據。目前我們對 2018 年已有下列資訊:

  • 市場需求分析預期,因為 Model 3 銷量提升,2018 年的收入將增加到 13,000。

本練習屬於課程

使用 Python 進行財務預測

檢視課程

練習說明

  • 建立僅包含 revenue_metric 這一列的篩選後損益表。
  • 使用 columns 屬性的長度(len())取得 filtered_income_statement 的欄位數。
  • filtered_income_statement 中插入一個新欄位。
    • 將它放在列的最後(使用 n_cols 作為 loc)。
    • 欄位名稱使用 'Forecast'
    • 插入數值 13000
  • 印出結果。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

revenue_metric = ['Revenue']

# Filter for rows containing the revenue metric
filtered_income_statement = ____[____.____.____(____)]

# Get the number of columns in filtered_income_statement
n_cols = ____(filtered_income_statement.____)

# Insert a column in the correct position containing the column 'Forecast'
filtered_income_statement.insert(____, '____', ___) 

# See the result
print(filtered_income_statement)
編輯並執行程式碼