Fix My Tutorial
Report

Practical Business Python

Open the original tutorial
Fixed Python 3.12 · checked 17 Oct 2026 · model cost $0.077

The tutorial code initially failed because pandas no longer provides DataFrame.from_items and the XlsxWriter engine lacks a save() method. After replacing the deprecated DataFrame factory with the DataFrame constructor and using a context manager for pd.ExcelWriter, the script runs successfully under Python 3.12.

7 changes to make it work today

Create DataFrame from dictionary of lists

s4 · run_code migrate

pd.DataFrame.from_dict was removed; the DataFrame constructor accepts a dict of column->list directly.

@@ -3,3 +3,3 @@
'Feb': [200, 210, 90],
'Mar': [140, 215, 95]}
-df = pd.DataFrame.from_dict(sales)
+df = pd.DataFrame(sales)

Sources

Create DataFrame from OrderedDict

s6 · run_code migrate

pd.DataFrame.from_dict was removed; the DataFrame constructor accepts an OrderedDict the same way.

@@ -3,3 +3,3 @@
('Feb', [200, 210, 90]),
('Mar', [140, 215, 95]) ] )
-df = pd.DataFrame.from_dict(sales)
+df = pd.DataFrame(sales)

Sources

Create DataFrame from records

s7 · run_code migrate

pd.DataFrame.from_records was removed; the DataFrame constructor accepts a list of rows with a columns argument.

@@ -3,3 +3,3 @@
('Blue Inc', 140, 215, 95)]
labels = ['account', 'Jan', 'Feb', 'Mar']
-df = pd.DataFrame.from_records(sales, columns=labels)
+df = pd.DataFrame(sales, columns=labels)

Sources

Create DataFrame from items (first example)

s8 · run_code migrate

pd.DataFrame.from_items was removed; converting the list of (key, value) pairs to a dict and passing to the constructor produces the same DataFrame.

@@ -4,3 +4,3 @@
('Mar', [140, 215, 95]),
]
-df = pd.DataFrame.from_items(sales)
+df = pd.DataFrame(dict(sales))

Sources

Create DataFrame from items (second example)

s9 · run_code migrate

pd.DataFrame.from_items was removed; converting the list of (key, value) pairs to a dict and passing to the constructor produces the same DataFrame.

@@ -4,3 +4,3 @@
('Mar', [140, 215, 95]),
]
-df = pd.DataFrame.from_items(sales)
+df = pd.DataFrame(dict(sales))

Sources

Create footer DataFrame

s10 · run_code migrate

pd.DataFrame.from_items was removed; converting the list of (key, value) pairs to a dict and passing to the constructor produces the same DataFrame.

@@ -4,3 +4,3 @@
created_by = "CM"
footer = [('Created by', [created_by]), ('Created on', [create_date]), ('Version', [1.1])]
-df_footer = pd.DataFrame.from_items(footer)
+df_footer = pd.DataFrame(dict(footer))

Sources

Write DataFrames to Excel

s11 · run_code migrate

The xlsxwriter engine does not have a save() method (see evidence r2e1). Using a with statement ensures the workbook is properly closed and saved.

@@ -1,4 +1,3 @@
-writer = pd.ExcelWriter('simple-report.xlsx', engine='xlsxwriter')
-df.to_excel(writer, index=False)
-df_footer.to_excel(writer, startrow=6, index=False)
-writer.save()
+with pd.ExcelWriter('simple-report.xlsx', engine='xlsxwriter') as writer:
+ df.to_excel(writer, index=False)
+ df_footer.to_excel(writer, startrow=6, index=False)

Sources

Tell the author

Send them what broke and the fix, so the next reader doesn't hit the same error.

Badge

Add it to the tutorial so readers know when it was last checked.

Fix My Tutorial badge
Markdown
[![Fix My Tutorial](https://fix-my-tutorial.onrender.com/badge/ri-str4U2QJ.svg)](https://fix-my-tutorial.onrender.com/r/ri-str4U2QJ)
HTML
<a href="https://fix-my-tutorial.onrender.com/r/ri-str4U2QJ"><img src="https://fix-my-tutorial.onrender.com/badge/ri-str4U2QJ.svg" alt="Fix My Tutorial"></a>