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


Messages In This Thread
df.loc question - by Led_Zeppelin - Sep-15-2022, 06:26 PM
RE: df.loc question - by deanhystad - Sep-15-2022, 07:10 PM

Forum Jump:

User Panel Messages

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