Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why the NameError?
#1
Hi all,

In Jupyter Notebook I ran these cells:

sample_data = [[3000,18], [3200,17], [3500,16], [4000,12]]
sample_df = pd.DataFrame(sample_data, columns = ['SPX', 'Spread_Price'])
Next, I ran this as a single cell:

fig, axs = plt.subplots()
axs.plot(sample_df['SPX'])
axs.twinx()
axs.plot(sample_df['Spread_Price'])
plt.show()
This gave me a graph. Before I get into what's wrong with the graph, I want to point out that it had no problem processing the df still in memory from the cell just ran before. This is how JN usually works and one reason I really like it.

However, earlier this morning I ran my full 350-line program before pasting the last 55 lines into a separate file. This is the portion of the program responsible for the graphing. I got NameError. First, plt was not defined even though running the full program included "import matplotlib.pyplot as plt". After adding that on top of the separate file, I got btstats---name of the dataframe defined in the full program--not defined. Any ideas as to why these names might not have been retrievable from memory since I had run them previously in this JN session (e.g. I didn't shut down the kernel, close the tab, or otherwise reset JN)?
Reply


Messages In This Thread
Why the NameError? - by Mark17 - May-16-2022, 02:27 PM
RE: Why the NameError? - by jefsummers - May-16-2022, 04:34 PM
RE: Why the NameError? - by Mark17 - May-16-2022, 04:48 PM
RE: Why the NameError? - by Mark17 - May-16-2022, 05:09 PM
RE: Why the NameError? - by Mark17 - May-17-2022, 08:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  NameError: NameError: global name 'BPLInstruction' is not defined colt 7 4,528 Oct-27-2019, 07:49 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020