Python Forum
Urgent homework help needed - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Urgent homework help needed (/thread-31110.html)



Urgent homework help needed - Medou - Nov-23-2020

Dear Python lovers,

I am in urgent need of some assistance. I am stuck with a seemingly simple task, just can't wrap my head around the slicing part for some reason:/

My task is:

Create a dictionary and name it cc. The dictionary has two keys: data and target, and the corresponding key values are NumPy arrays. For target, the key value is an array of values from the encoded column satisfaction of df. For data, the key value is an array of sub arrays and each sub array is an observation of one sample across the features in df2.

My code is:

cc = {
    "data": df_final_pd.iloc[:0, :].to_numpy(),
    "target": df_final_pd["satisfaction"].to_numpy(),
}
cc
It gives me a NameError: name 'df_final_pd' is not defined but I am not sure if the slicing is ok? Also, 'df_final_pd' is previously defined. It's so weird.

Please help!


RE: Urgent homework help needed - perfringo - Nov-23-2020

You can be pretty sure that if Python says NameError (name not defined) then Python is correct and you are not. Nothing more can be said as we know next to nothing about your code.


RE: Urgent homework help needed - Medou - Nov-24-2020

(Nov-23-2020, 10:49 PM)perfringo Wrote: You can be pretty sure that if Python says NameError (name not defined) then Python is correct and you are not. Nothing more can be said as we know next to nothing about your code.

Python was wrong in this case. It turned out that I just needed to re-run all the lines & it worked without touching the code. Thanks for your input though:)

M.


RE: Urgent homework help needed - perfringo - Nov-24-2020

I can assure you that earth is not flat and center of the universe. It's another story whether you believe me or not. If line which defined name was not run how Python should have known about this name and whose fault it is?

In case you used Jupyter and didn't restart kernel between your 'runs' then you code could still raise NameError when it is executed first time.


RE: Urgent homework help needed - buran - Nov-24-2020

Not to mention Jupyter is not mentioned anywhere in first post, nor that full traceback was not provided