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

**URL:** <https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107>\
**Category:** General Usage\
**Tags:** question, package, dictionary, dataframes\
**Created:** [May 31, 2021, 4:35am UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107 "2021-05-31T04:35:52Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 6:26pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/21 "2021-06-01T18:26:53Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 6:41pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/22 "2021-06-01T18:41:10Z")

</div>

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

```julia
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

```

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 7:01pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/23 "2021-06-01T19:01:04Z")

</div>

I want a new dataframe for each journal entry

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [June 1, 2021, 7:06pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/24 "2021-06-01T19:06:47Z")

</div>

> [@brett\_knoss](#):
>
> ```julia
> Symbol(journalentry)=DataFrame(Date=[newddate], 
> Debited_Account=[""],
> Credited_Account=[""],
> Credit=[0],
> Debit=[0],
> Balance=[0])
> 
> ```

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](https://docs.julialang.org/en/v1/manual/functions/) of the documentation.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 7:11pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/25 "2021-06-01T19:11:30Z")

</div>

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

How do I fix it?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 7:24pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/26 "2021-06-01T19:24:42Z")

</div>

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

 ![phpx2XoSI](https://global.discourse-cdn.com/julialang/original/3X/3/7/37dec6b7a93441a6be1eb869cb48141ae404fce0.png)  
as a dataframe

and this  
 ![newstyletransactions2](https://global.discourse-cdn.com/julialang/original/3X/9/b/9b96aa2efda0246c9271219380f417fc278dfa82.png)  
as a dataframe

with one line of code.

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [June 1, 2021, 7:28pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/27 "2021-06-01T19:28:14Z")

</div>

The line

```julia
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?

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 7:37pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/28 "2021-06-01T19:37:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [June 1, 2021, 8:22pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/30 "2021-06-01T20:22:36Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 8:26pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/31 "2021-06-01T20:26:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 8:33pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/32 "2021-06-01T20:33:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [June 1, 2021, 8:39pm UTC](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107/33 "2021-06-01T20:39:48Z")

</div>

I created a new thread  
[Creating an Accounting Program in Julia, for Pluto](https://discourse.julialang.org/t/creating-an-accounting-program-in-julia-for-pluto/62227)

[Previous page](https://discourse.julialang.org/t/use-a-string-for-a-variable-name-and-convert-dictionaries-to-dataframes/62107.md?page=1)
