Depreciation_DM = model.constant("Depreciation_DM")
Depreciation_DM.equation = 0.0708
DMPIncRate = model.constant("DMPIncRate")
DMPIncRate.equation = 0.0284
DMPInc = model.flow("DMPInc")
DM_Price = model.stock("DM_Price")
DM_Price.initial_value = 4.2e+07
DM_Price.equation = DMPInc
DMPInc.equation = DM_Price * DMPIncRate
Average_Expected_Years_Kept_Battery_DM = model.constant("Average_Expected_Years_Kept_Battery_DM")
Average_Expected_Years_Kept_Battery_DM.equation = 6.0
Depreciation_Battery_DM = model.constant("Depreciation_Battery_DM")
Depreciation_Battery_DM.equation = 0.00033
Battery_Price_DM = model.converter("Battery_Price_DM")
Battery_Price_DM.equation = 0.25 * DM_Price
Battery_Resale_DM = model.converter("Battery_Resale_DM")
Battery_Resale_DM.equation = ((Charging_Frequency_DM * Average_Expected_Years_Kept_Battery_DM)* Depreciation_Battery_DM) * Battery_Price_DM
Discount_Rate_DM = model.constant("Discount_Rate_DM")
Discount_Rate_DM.equation = 0.0838
Battery_Resale_DM = model.converter("Battery_Resale_DM")
Battery_Resale_DM.equation = (
(Charging_Frequency_DM * Average_Expected_Years_Kept_Battery_DM) *
Depreciation_Battery_DM
) * Battery_Price_DM
Resale_Value_DM = model.converter("Resale_Value_DM")
Resale_Value_DM._function_string = (
"lambda model, t: ("
"pow(1.0 - model.memoize('Depreciation_DM', t), "
"model.memoize('Average_Expected_Years_Kept_DM', t))"
"* model.memoize('DM_Price', t)"
"+ model.memoize('Battery_Resale_DM', t)"
") / "
"pow(1.0 + model.memoize('Discount_Rate_DM', t), "
"(model.memoize('Average_Expected_Years_Kept_DM', t) - 1.0))"
)
Resale_Value_DM.generate_function()
Purchase_Tax_Subsidy_DM_pct = model.converter("Purchase_Tax_Subsidy_DM_pct")
Purchase_Tax_Subsidy_DM_pct._function_string = (
"lambda model, t: 0.11 if t < 2023.0 else 0.01"
)
Purchase_Tax_Subsidy_DM_pct.generate_function()
Price_Subsidy_DM = model.converter("Price_Subsidy_DM")
Price_Subsidy_DM._function_string = (
"lambda model, t: 0.0 if t < 2023.0 else 7e+06"
)
Price_Subsidy_DM.generate_function()
Purchase_Cost_After_Subsidies_DM = model.converter("Purchase_Cost_After_Subsidies_DM")
Purchase_Cost_After_Subsidies_DM.equation = ((DM_Price - Price_Subsidy_DM) + (Purchase_Tax_Subsidy_DM_pct * DM_Price))
model.points["PKB_%_DM_Subsidy"] = [
[2015, 0.02],
[2016, 0.02],
[2017, 0.02],
[2018, 0.02],
[2019, 0.02],
[2020, 0.02],
[2021, 0.002],
[2022, 0.002],
[2023, 0.0],
[2024, 0.0],
[2025, 0.0],
[2026, 0.0],
[2027, 0.0],
[2028, 0.0],
[2029, 0.0],
[2030, 0.0],
[2031, 0.0],
[2032, 0.0],
[2033, 0.0],
[2034, 0.0],
[2035, 0.0],
]
PKB_pct_DM_Subsidy = model.converter("PKB_%_DM_Subsidy")
PKB_pct_DM_Subsidy.equation = sd.lookup(sd.time(), "PKB_%_DM_Subsidy")
SWDKLLJ = model.constant("SWDKLLJ")
SWDKLLJ.equation = 35000.0
Yearly_Tax_Cost_DM_After_Subsidies = model.converter("Yearly_Tax_Cost_DM_After_Subsidies")
Yearly_Tax_Cost_DM_After_Subsidies._function_string = (
"lambda model, t: ("
"model.memoize('PKB_%_DM_Subsidy', t) * "
"pow(1.0 - model.memoize('Depreciation_DM', t), (t - 2014.0 - 1.0)) * "
"model.memoize('Resale_Value_DM', t)"
") + model.memoize('SWDKLLJ', t)"
)
Yearly_Tax_Cost_DM_After_Subsidies.generate_function()
First I used the first script and the result was an error,...
bptk.plot_scenarios(
scenarios="base",
scenario_managers="smDm vs cm",
equations=["Yearly_Tax_Cost_DM_After_Subsidies"],
series_names={},
return_df=True)
2025-11-03 16:00:25.551125, [ERROR] No output data produced.**
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipython-input-2983896965.py in <cell line: 0>()
30 #PKB_pct_DM_Subsidy* ((1.0 - Depreciation_DM) ** (Time - 2014 - 1))* Resale_Value_DM) + SWDKLLJ
31
---> 32 bptk.plot_scenarios(
33 scenarios="base",
34 scenario_managers="smDm vs cm",
________________________________________
1 frames
________________________________________
/usr/local/lib/python3.12/dist-packages/BPTK_Py/visualizations/visualize.py in plot(self, df, return_df, visualize_from_period, visualize_to_period, stacked, kind, title, alpha, x_label, y_label, start_date, freq, series_names, format)
63
64 new_columns = {}
---> 65 for column in df.columns:
66 for series_names_key in series_names_keys:
67 if series_names_key in column:
AttributeError: 'NoneType' object has no attribute 'columns'
After I was diagnosed with the second script, it turned out that the value for "Yearly_Tax_Cost_DM_After_Subsidies" actually exists.
print("PKB 2015→", model.memoize("PKB_%_DM_Subsidy", 2015.0))
print("Resale 2015→", model.memoize("Resale_Value_DM", 2015.0))
print("SWDKLLJ 2015→", model.memoize("SWDKLLJ", 2015.0))
print("Tax DM 2015→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2015.0))
print("Tax DM 2016→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2016.0))
print("Tax DM 2017→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2017.0))
print("Tax DM 2018→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2018.0))
print("Tax DM 2019→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2019.0))
print("Tax DM 2020→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2020.0))
print("Tax DM 2021→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2021.0))
print("Tax DM 2022→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2022.0))
print("Tax DM 2035→", model.memoize("Yearly_Tax_Cost_DM_After_Subsidies", 2035.0))
PKB 2015→ 0.02
Resale 2015→ 20247218.066840753
SWDKLLJ 2015→ 35000.0
Tax DM 2015→ 439944.36133681505
Tax DM 2016→ 421960.49068990693
Tax DM 2017→ 404775.2966868149
Tax DM 2018→ 388353.30952273984
Tax DM 2019→ 372660.63463245216
Tax DM 2020→ 357664.882732768
Tax DM 2021→ 65833.51029718903
Tax DM 2022→ 64464.17190476344
Tax DM 2035→ 35000.0
However, I need the first script for my simulation because there are still many other columns in my simulation that depend on the value in the "Yearly_Tax_Cost_DM_After_Subsidies" column. Why does the error AttributeError: 'NoneType' object has no attribute 'columns' occur???
```to format block of code/output/error (instead of>and**) to make them more readable. And use`to format inline code.dfis None. You could check code beforerdf.columnsin filevisualize.pyto see how it createsdf. Maybe this can explain why it isNone.run_scenarios()shows that it writes some messages inlog. And it seems you get it in your output[ERROR] No output data produced.. (and it seems it sends this messsage whenlen(df) == 0) You can debug this function to see why it didn't create output data.df = None? Have you considered stepping through your code to help debug? Check out How to Ask for tips on writing a good title and more.