I am trying to create a malware classifier and I am experiencing the error
AttributeError: 'Series' object has no attribute 'Id. Not sure of the error.
Traceback (most recent call last):
File"C:/Users/Afiqmatters/PycharmProjects/MajorProject/feature_extraction.py", line 23, in <module>
rids = [mids.loc[i].Id for i in rchoice]
File "C:\Users\Afiqmatters\Miniconda\lib\site-packages\pandas\core\generic.py", line 2744, in __getattr__
return object.__getattribute__(self, name)
AttributeError: 'Series' object has no attribute 'Id'
Here is the codes I have up to the error.
rs = Random()
rs.seed(1)
trainLabels = pd.read_csv('trainLabels.csv')
#print trainLabels
fids = []
opd = pd.DataFrame()
for label in range(1,10):
mids = trainLabels[trainLabels.Class == label]
mids = mids.reset_index(drop=True)
#print mids
rchoice = [rs.randint(0, len(mids) - 1) for i in range(10)]
print len
#print rchoice
rids = [mids.loc[i].Id for i in rchoice]
The error happens at rids = [mids.loc[i].Id for i in rchoice] and I am not sure of the error.
A sample of what is stored in the trainLabels.csv
Id Class
0A32eTdBKayjCWhZqDOQ 2
mids.loc[i] in this context is a "Series" object which is detailed here
This object type does not have an attribute Series.Id, so that's why you're seeing this error.
Did you mean to call the built-in function id( ) on the object?
rids = [id(mids.loc[i]) for i in rchoice]
Related
I'm trying to add try and except to my code but it does not work.
def _get_table_df(self, table):
l = module.send_command(name='Read', attributes={'type': table, 'method':'all', 'limit':'1', 'enable_custom':1})
so = BeautifulSoup(l.text,'xml')
columns = []
try:
for x in list(so.find(table).children):
columns.append(x.name)
df = pd.DataFrame(columns=columns)
except AttributeError:
return "no data"
return df
The error pointing to try line says
AttributeError: 'NoneType' object has no attribute 'children'
def fetchAndUpdateAllOrderDetails(self, orders):
fyers = self.brokerHandle
orderBook = None
try:
orderBook = fyers.orderbook()
except Exception as e:
logging.error('%s Failed to fetch order book', self.broker)
return
logging.info('%s Order book length = %d', self.broker, len(orderBook))
numOrdersUpdated = 0
for bOrder in orderBook:
foundOrder = None
for order in orders:
if order.orderId == bOrder['orderBook']['id']:
foundOrder = order
break
if foundOrder != None:
def fetchAndUpdateAllTradeOrders():
allOrders = []
for trade in TradeManager.trades:
if trade.entryOrder != None:
allOrders.append(trade.entryOrder)
if trade.slOrder != None:
allOrders.append(trade.slOrder)
if trade.targetOrder != None:
allOrders.append(trade.targetOrder)
TradeManager.getOrderManager().fetchAndUpdateAllOrderDetails(orders = allOrders)
It returns the error:
Traceback (most recent call last):
File "d:\AlgoTraderFyers\src\trademgmt\TradeManager.py", line 76, in run
TradeManager.fetchAndUpdateAllTradeOrders()
File "d:\AlgoTraderFyers\src\trademgmt\TradeManager.py", line 227, in fetchAndUpdateAllTradeOrders
TradeManager.getOrderManager().fetchAndUpdateAllOrderDetails(orders = allOrders)
AttributeError: 'NoneType' object has no attribute 'fetchAndUpdateAllOrderDetails'
It was working with the other broker(zerodha). Pls help!
AttributeError: 'NoneType' object has no attribute 'fetchAndUpdateAllOrderDetails'
This means that the thing you are calling the fetchAndUpdateAllOrderDetails() function on is "None".
So in this case, the return value of TradeManager.getOrderManager() is None.
Are you returning anything from the getOrderManager() function?
I don't success to fix this error on my code. Python wrote me this error message:
"Traceback (most recent call last):
File "C:\Users\ChloƩ CHAUMETON\Documents\BioAxial\1_R&D\4_Software\2_Python\Measurement_script\Matlab_to_Python\2019\Chloe_script_V3.py", line 114, in <module>
if 0 < len((lrir)(lrir.name_file)):
AttributeError: 'function' object has no attribute 'name_file' "
I defined the "name_file = 'BSR_Main.exe2018_09_14.csv' " up of my code but I don't understand why python don't attribute this name fto the function. Here is my code.
i_r=[]
def lrir():
lrir = liste_record[i_r]
name_file = 'BSR_Main.exe2018_09_14.csv';
for i_r in range(0,rec-1):
if 0 < len((lrir)(lrir.name_file)):
str1 = ligne.find(lrir.name_file,'/')
pr_rep = os.path.join(dir_PR,s(i_r).name_file)
log_rep = os.path.join(pr_rep,'Log')
log_file = glob.glob(os.path.join(log_rep,'*.log'))
print('log file:',log_file)
When I run this code:
def printPredictions(matches):
pPredictionTable = PrettyTable()
pPredictionTable.field_names = ["Player 1", "Player 2", "Difference", "Winner"]
for match in matches:
p1 = match['teamA']
p2 = match['teamB']
if match['aBeatb'] == True:
pPredictionTable.add_row([match['teamA'], match['teamB'], match['difference'], p1])
else:
pPredictionTable.add_row([match['teamA'], match['teamB'], match['difference'], p2])
print(pPredictionTable)
printPredictions(pmatches)
I get this error:
Traceback (most recent call last):
File "C:\Users\ericr_000\Desktop\PyDev\NPA-2-Rating-System\Rankings.py", line 645, in <module>
printPredictions()
TypeError: 'str' object is not callable
I have pmatches as a separate dictionary, and I don't have the coding skills to fix this issue. (Line 145 is printPredictions(pmatches)
If you're getting 'str' object is not callable when you try to call printPredictions, that means that by the time your program reaches line 645, the name printPredictions was reassigned to a string. Somewhere in your code you have something like
printPredictions = someStringValueGoesHere
You should choose a different name for that variable, or delete the line entirely.
foobar = someStringValueGoesHere
I am retrieving the last id from mssql and trying to incrementing it and storing the fie name with the id.. But I am getting "Attribute error : Nonetype object has no attribute 'id'"..The code and the error goes here :
import Tkinter,tkFileDialog
import shutil
import pyodbc
cnxn = pyodbc.connect("DRIVER={SQL Server};SERVER=PAVAN;DATABASE=video;Trusted_Connection=yes;")
cursor = cnxn.cursor()
cursor.execute("SELECT TOP 1 id FROM files ORDER BY id DESC ")
while 1:
row = cursor.fetchone()
if not row:
break
print row.id
cnxn.close()
middle = Tkinter.Tk()
def withdraw():
dirname = tkFileDialog.askopenfilename(parent=middle,initialdir="H:/",title='Please
select a file')
a="H:python(test)\py_"+row.id+".mp4"
b=shutil.copyfile(dirname,a)
if b!="":
print "Successfully Copied"
else:
print "Could not be copied"
B = Tkinter.Button(middle, text ="UPLOAD", command = withdraw)
middle.geometry("450x300+100+100")
middle.configure(background="black")
B.pack()
middle.mainloop()
The error I'm getting is:
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1470, in __call__
return self.func(*args)
File "C:\Users\hp\Desktop\upload.py", line 20, in withdraw
a="H:python(test)\py_"+row.id+".mp4"
AttributeError: 'NoneType' object has no attribute 'id'
This occurs when the you try to get id Attribute from object which is of None type ,
Here is a case :
>> a = None
>> a.id
AttributeError: 'NoneType' object has no attribute 'id'
So it might be the case object row is of None type , and you are trying to print row.id
You may check for the type of row using :
type(**row**)
With Regards
Deepak