Python Forum
Urgent homework help needed
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Urgent homework help needed
#1
Heart 
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!
buran write Nov-24-2020, 09:26 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
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.
buran likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#3
(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.
Reply
#4
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.
buran likes this post
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy

Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Reply
#5
Not to mention Jupyter is not mentioned anywhere in first post, nor that full traceback was not provided
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Exclamation Python Homework (Urgent help needed!!) chickenseizuresalad 6 4,214 Oct-11-2021, 01:59 AM
Last Post: Underscore
Exclamation urgent , Python homework alm 2 2,257 May-09-2021, 11:19 AM
Last Post: Yoriz
  urgent I got a syntax errors alm 2 5,792 Feb-28-2021, 02:54 PM
Last Post: alm
  [Urgent] build code GodMaster 2 1,766 Mar-23-2020, 12:25 AM
Last Post: jefsummers
  Bifid Genkey (Urgent) Laura123 2 2,016 Mar-09-2020, 08:09 PM
Last Post: micseydel
  Python Homework Help *Urgent GS31 2 2,537 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Need help! Please! Urgent! foxylen 1 2,260 Feb-27-2019, 05:50 PM
Last Post: buran
  (Not urgent) IDLE issue with methods vinfer12 5 3,882 Mar-22-2018, 09:00 PM
Last Post: Gribouillis
  Machine Learning Antivirus [Urgent] Echoo0o 4 4,846 Jul-28-2017, 01:57 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

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