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