# Dataframe recalculation and plot

**URL:** <https://discourse.julialang.org/t/dataframe-recalculation-and-plot/112412>\
**Category:** General Usage\
**Tags:** dataframes, plots\
**Created:** [April 2, 2024, 11:11am UTC](https://discourse.julialang.org/t/dataframe-recalculation-and-plot/112412 "2024-04-02T11:11:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stephen](https://avatars.discourse-cdn.com/v4/letter/s/96bed5/32.png) [@Stephen](https://discourse.julialang.org/u/Stephen)\
**Post date:** [April 2, 2024, 11:11am UTC](https://discourse.julialang.org/t/dataframe-recalculation-and-plot/112412/1 "2024-04-02T11:11:24Z")

</div>

```julia
using XLSX, DataFrames, PlotlyJS, Dates, Statistics

df = coalesce.(DataFrame(XLSX.readtable("台湾.xlsx","财政税收")), 0.0)

# coalesce将missing替换为浮点数0.0

###########
# 各项税收
###########

scatter_data = GenericTrace{Dict{Symbol, Any}}[];
proportion_tax = DataFrame()
for col in names(df)[3:end]
    proportion_tax[!, col] .= df[!, col]./df.總計
    if any(proportion_tax[!, col] .> 0.05)
        push!(scatter_data, scatter(x = df.統計期, y = proportion_tax[!,col], name = col))
    end
end

```

In this for loop, the proportion of various taxes to the total tax income is recalculated and assigned to another Dataframe `proportion_tax`， how should I pre-define the `proportion_tax` to avoied error?

```julia
p = plot(
    scatter_data,
    Layout(
        title = "占比超过5%的各项税收",
        xaxis = attr(dtick = "M12", tickangle = -45, tickformat="%b\n%Y")
    )
)

```

In addition，if I want to plot the latest data, for example the last 10 years rather than all the data, what shoud I modify my code?
