Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
df.loc question
#1
In the following code which as you can see there is one dataframe.

q = df.loc[df2['machine_status']==0]['sensor_06']
p = df.loc[df2['machine_status']==1]['sensor_06'][:q.shape[0]]

pp = sm.ProbPlot(p)
pq = sm.ProbPlot(q)
qqplot_2samples(pp,pq)
plt.title("Q-Q plot of sensor_6 for machine_statuts")
plt.show()
I take the term to be a complete function when working on a dataframe. In this case data it is working on is df2. I know that they could use more meaningful names but bear with me. This works as shown in the attachment.

But when I use the following code which is very similar to the above code, I get an error.

The code is:
Output:
NameError Traceback (most recent call last) Input In [7], in <cell line: 1>() ----> 1 q = df.loc[df2['machine_status']==0]['time_period'] 2 p = df.loc[df2['machine_status']==1]['time_period'][:q.shape[0]] 4 pq = np.sum(p * np.log(p/q)) NameError: name 'df' is not defined
I am using the function in the same program in the same environment. It likes the first but does not like the second.

I need to know what to put in the fix this condition on the second function.

Respectfully,

LZ
Reply
#2
define "df"?

This statement is incorrect:
Quote:In this case data it is working on is df2.
You are "working on" df and df2 and the error message says there is no variable named "df".

Has your code assigned a value to df? Where did that happen? Did it happen before trying to use df? Was it in the same scope as the code that is trying to use df?

Are you runnning in a notebook?
ndc85430 likes this post
Reply


Forum Jump:

User Panel Messages

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