Apr-01-2020, 05:24 PM
I am trying to make a class I can use to save a dataframe, two strings and two floats.
I cant seem to get it to work.
Defocus Tan Sag
8 -50.8 9.2 10.1
9 -24.7 29.8 30.1
10 0.7 39.4 39.5
11 25.6 29.9 31.5
12 50.1 11.5 14.5
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-197-163bba125617> in <module>
3 DefocusPlane = (df.iloc[(x+2):(x+2+DefocusPlanes[x]), 1:4])
4 print (DefocusPlane)
----> 5 SingleRunData.AddDefocusPlane(DefocusPlane, FieldAngle, DefocusFrequency, Title, local_time)
6 RunData.append(SingleRunData)
<ipython-input-194-9edb5b7dd6ac> in AddDefocusPlane(DefocusPlane, FieldAngle, DefocusFrequency, Title, local_time)
7 self.LP = -1
8 def AddDefocusPlane(DefocusPlane, FieldAngle, DefocusFrequency, Title, local_time):
----> 9 self.DFAngSagTang = DefocusPlane
10 self.FileName = Title
11 self.Date = local_time
NameError: name 'self' is not defined
-=-=-=
I get the following errors. Any help would be great , thank you. New Bee
I cant seem to get it to work.
import numpy as np
import os
import matplotlib
import matplotlib.pyplot as plt
matplotlib.use('wxAgg') # matplotlib backend needed to work with wxPython GUI
import time
from datetime import datetime
import pandas as pd
selected_dir = r"C:\Users\cstreb\Desktop\Data Visualization"
path = r"C:\Users\cstreb\Desktop\Data Visualization\Test1.xlsm"
df = pd.read_excel (path, sheet_name='DefocusData', names = ["Description","Defocus","Tan","Sag"])
Title = os.path.basename(path)
print (Title)
Time = os.path.getmtime(path)
local_time = time.ctime(Time)
print("Last modification time(Local time):", local_time)
FieldAngles = ((df.loc[df['Description'] == 'THF Field Angle, Roll Angle']).iloc[:,1])
DefocusPlanes = ((df.loc[df['Description'] == 'Number of THF Planes']).iloc[:,1])
DefocusFrequency = ((df.loc[df['Description'] == 'Defocus Frequency']).iloc[:,1])
print (DefocusFrequency)
for x in DefocusPlanes.index:
print (x)
print (df.iloc[(x+3):(x+3+DefocusPlanes[x]), 1:4])
class geeks:
def __init__(self):
self.DFAngSagTang = pd.dataframe
self.FileName = ""
self.Date = ""
self.FieldAngle = -1
self.LP = -1
def AddDefocusPlane(DefocusPlane, FieldAngle, DefocusFrequency, Title, local_time):
self.DFAngSagTang = DefocusPlane
self.FileName = Title
self.Date = local_time
self.FieldAngle = FieldAngle
self.LP = DefocusFrequency
for x in DefocusPlanes.index:
FieldAngle = (FieldAngles[x-1])
DefocusPlane = (df.iloc[(x+2):(x+2+DefocusPlanes[x]), 1:4])
print (DefocusPlane)
SingleRunData.AddDefocusPlane(DefocusPlane, FieldAngle, DefocusFrequency, Title, local_time)
RunData.append(SingleRunData)I get the following error -=-=-=-=-=-=-=-=-Defocus Tan Sag
8 -50.8 9.2 10.1
9 -24.7 29.8 30.1
10 0.7 39.4 39.5
11 25.6 29.9 31.5
12 50.1 11.5 14.5
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-197-163bba125617> in <module>
3 DefocusPlane = (df.iloc[(x+2):(x+2+DefocusPlanes[x]), 1:4])
4 print (DefocusPlane)
----> 5 SingleRunData.AddDefocusPlane(DefocusPlane, FieldAngle, DefocusFrequency, Title, local_time)
6 RunData.append(SingleRunData)
<ipython-input-194-9edb5b7dd6ac> in AddDefocusPlane(DefocusPlane, FieldAngle, DefocusFrequency, Title, local_time)
7 self.LP = -1
8 def AddDefocusPlane(DefocusPlane, FieldAngle, DefocusFrequency, Title, local_time):
----> 9 self.DFAngSagTang = DefocusPlane
10 self.FileName = Title
11 self.Date = local_time
NameError: name 'self' is not defined
-=-=-=
I get the following errors. Any help would be great , thank you. New Bee
