I want to create a DataFrame to which I want to import data from a class. I mean, I type t1 = Transaction("20221128", "C1", 14) and I want a DataFrame to show data like:
- Column 1: Date
- Column 2: Concept
- Column 3: Amount
The code where I want to implement this is:
class Transactions:
num_of_transactions = 0
amount = 0
def __init__(self, date, concept, amount):
self.date = date
self.concept = concept
self.amount = amount
Transaction.add_transaction()
Transaction.add_money(self)
@classmethod
def number_of_transactions(cls):
return cls.num_of_transactions
@classmethod
def add_transaction(cls):
cls.num_of_transactions += 1
@classmethod
def amount_of_money(cls):
return cls.amount
@classmethod
def add_money(cls, self):
cls.amount += self.amount
t1 = Transaction("20221128", "C1", 14)
t2 = Transaction("20221129", "C2", 30)
t3 = Transaction("20221130", "3", 14)
I tried:
def DataFrame(self):
df = pd.DataFrame(self.date self.concept, self.amount)
But looking at pandas documentation, I have seen it is not a valid way.
Any help on that? Thank you!