Use a String For a Variable name and convert Dictionaries to DataFrames

I fixed that, but now it’s saying that I can’t have have Symbol(debit_account) as the name of a column

 Symbol(journalentry)=DataFrame(Date=[newddate], 
		                          Symbol(debit_account)=[0],
		                          Symbol(credit_account)=[0],
		                          balance=[0])

I think I have it fixed, but I can’t test it. How do I do push! if I have a DataFrame or DataFrames?

function transaction(date,journalentry, debit_account, debit_amount, credit_account, credit_amount)
    if debit_amount != credit_amount
        error("Debit ($debit_amount) and credit ($credit_amount) must match")
    end

    # Prepare row as named tuple, starting with zero values overwritten by values for the specified accounts
    new_row = (; (Symbol.(names(accounts)) .=> 0)...,
                 Symbol(debit_account, "_debit") => debit_amount,
                 Symbol(credit_account, "_credit") => credit_amount)
	
    push!(accounts, new_row)

   Symbol(journalentry)=DataFrame(Date=[newddate], 
		                          Debited_Account=[""],
		                          Credited_Account=[""],
								  Credit=[0],
								  Debit=[0],
		                          Balance=[0])
	push!(journalentry, ( Date="",
						   Debited_Account=debit_account,
			               Credited_Account=0,
			               Debit=debit_amount,
			               Credit=0,
			               Balance=0))
push!(journalentry, ( Date="",
						   Debited_Account="",
			               Credited_Account=credit_account,
			               Debit=0,
			               Credit=credit_ammount,
			               Balance=0))
end

I want a new dataframe for each journal entry

I know we keep telling you to read the documentation, but this line should be a red flag. Here you are re-defining the function Symbol(.), not constructing a data frame.

If you don’t understand why this syntax is doing that, please consult this section of the documentation.

5 Likes

I’m not finding any heading refrerencing Symbol(.)

How do I fix it?

I keep going in circles, do I use a macro, or do I use a function? How do I a get this


as a dataframe

and this
newstyletransactions2
as a dataframe

with one line of code.

The line

Symbol(journalentry)=...

defines a function, named Symbol, with a parameter journalentry. It returns a DataFrame in your case.
It’s not clear, what this line really should do, but surely not defining a function.

Well, I admit, I’m a bit lost in all these things. Perhaps we start again from a more clean beginning? We should not start with all the code you already have, because it already seems to be a bit confusing, at least to me. Perhaps it’s better to start with a clean table, and a minimal task to achieve. From where you can go further alone? I think it’s important, that you understand the underlying principles. Just providing you with working code is not what you really need. What do you think? Is this reasonable? Or is there just a single link missing I don’t see?

4 Likes

Probably best to start over. Although can I use $journal_entry in a journal?

ok, please start a new thread, with a minimal task. Your above screenshots a good start, together with some explanation. No code for now, or only minimal, like DataFrame initializations. Perhaps it would be nice, to know something about your background, like coming from R/Mathlab/SAS or similar, programming experience,… e.g.
And it would be good to know, in which environment you want to work, like: Pluto (I think you mentioned it somewhere).

Some R and SPSS, most of my experience is in Julia. My problem here is with how I’m using variables. I have practiced, and did take a computer class in Python, that went over the basic data types.

These examples are from different sources, but the ledger(bottom) has each account as a title. The journal(top) documents one transaction (a row in the ledger), with the Name of each account(the columns of the ledger) that is modified in the transaction.

To process a transaction the sums of credit and debit must match.

I created a new thread
Creating an Accounting Program in Julia, for Pluto