I have parsed data in dataframes by using Pandas. I need to insert the data into class that I created.
My class:
class Message:
time = None
id = None
type = None
source = None
destination = None
def __init__(self, time, id, type, source, destination):
self.time = time
self.id = id
self.type = type
self.source = source
self.destination = destination
I'm going through the dataframes and trying to insert the output into the attributes of the class as following:
newMessage=Message()
for index, row in df.iterrows():
newMessage.__init__(row['time'], row['id'], row['type'], row['source'], row['destination'])
print(row['time'], row['ID'], row['TYPE'], row['Source'], row['Destination'])
The exception it throws:
TypeError: __init__() missing 7 required positional arguments
I don't know how to call the class and the arguments, please help.
newMessage=Message()is trying to create aMessageobject, but you're not passing in any of the required arguments such astime,id, etc. It can't know what you want those values to be, so it gives an error. I'd suggest working through a python classes tutorial like w3schools.com/python/python_classes.asp