I’d like to know how to change the values of a dataframe, and ultimately a dataframe within a dictionary.
starting_balance=(
starting_balance["debit"]["assets"][account]=>(
DataFrame(
date=Vector{String}("31 Dec 2019"),
memo=Vector{String}("2019 closing balance"),
debit=Vector{Dec64}(2000.56),
credit=Vector{Dec64}(0),
balance=Vector{Dec64}(2567.67)))
#Now I want to change this to
starting_balance["debit"]["assets"][account]=>(
DataFrame(
date=Vector{String}("1 Jan 2020"),
memo=Vector{String}("2020 starting balance"),
debit=Vector{Dec64}(0),
credit=Vector{Dec64}(0),
balance=Vector{Dec64}(
starting_balance[end,:].balance)))
I know this is broken, but it should illustrate what I’m trying to do.
I guess if you change the structure of your DataFrame, you won’t need dictionary in the first place, currently your data are like
date | memo | debit | credit | balance
...
add three more columns
type1 | type2 | account | date | memo | debit | credit | balance
------|-------|...
debit | asset | acc |....
then you’ll have a long data frame and you can just manage it by DataFrames.jl APIs
I was using dictionaries to create a hiarchy of accounts
debit credit
drawings expenses assets liabilities equity revenue
actual accounts
I guess you kinda see that, I’m worried I would have to rewrite a bunch of stuff. All I want to do is move the balances from one year to another.
Do you want to append a row to a data frame or to update the last row of the data frame?
From your question I see you want to update the row, so it should be just:
starting_balance["debit"]["assets"][account][end, [:date, :memo, :debit, :credit]] = ["1 Jan 2020", "2020 starting balance", 0, 0]
If you want to append a row do:
push!(starting_balance["debit"]["assets"][account],
["1 Jan 2020", "2020 starting balance", 0, 0, starting_balance["debit"]["assets"][account].balance[end]])
No I want to delete everything and have 1 row with the final balance.
If you only want it to have the new row, it would be simplest to replace the dataframe in the dict with a new one. This assume you have no reference to the dataframe stored somewhere else.
I did a rewrite, but can this be done with a for loop?
If I understand what you want, I think all you need to do is
starting_balance["debit"]["assets"][account]=DataFrame(
date=Vector{String}("1 Jan 2020"),
memo=Vector{String}("2020 starting balance"),
debit=Vector{Dec64}(0),
credit=Vector{Dec64}(0),
balance=Vector{Dec64}(
starting_balance[end,:].balance))
There is no way that can work, since now I’m not telling it what DataFrame to use
I entered starting_balance[end,:].balance
and it just gave me a method error, as I expected.
Try this
starting_balance["debit"]["assets"][account]=DataFrame(
date=Vector{String}("1 Jan 2020"),
memo=Vector{String}("2020 starting balance"),
debit=Vector{Dec64}(0),
credit=Vector{Dec64}(0),
balance=Vector{Dec64}(balance))
But maybe that’s not what you want. It’s hard to tell.