【问题标题】:Julia Box plots, not reading columns where the csv file column that the name has spaces and parenthesis but has no problem reading 1word column titleJulia Box 绘图,不读取名称包含空格和括号的 csv 文件列但读取 1word 列标题没有问题的列
【发布时间】:2021-11-22 14:26:18
【问题描述】:

这是 Julia 中的代码

使用 CSV

使用数据帧

使用 PlotlyJS

df= CSV.read("path", DataFrame)

绘图(df, x=:Age, kind="box")

#我确实得到了这个的箱线图,因为在 csv 中该列以“年龄”为标题

plot(df, x=:年收入 (k$), kind="box")

错误:语法:参数列表中缺少逗号或 ) 堆栈跟踪: [1] 顶级范围 @无:1 #这里我收到一个询问语法的错误,但我不明白,因为 x= 部分正是该列的标签。如果我尝试 'x=:Annual' 我会得到一个什么都没有的箱线图,但列标题是“年收入 (k$)”。

非常感谢您的帮助!

参考:https://plotly.com/julia/box-plots/

【问题讨论】:

  • 请格式化您的代码

标签: csv julia julia-plots


【解决方案1】:

试试:


plot(df, x=Symbol("Annual Income (k\$)"), kind="box")

: 语法构造一个符号,但只能到下一个空格。所以:Annual Income (k$) 说要构建符号Symbol("Annual"),然后让Income (k$) 部分悬空。相反,您可以像上面一样自己显式构造符号。

$ 符号前的反斜杠是因为 Julia 通常使用 $ 进行插值,而这里我们想使用原始的 $ 字符本身。您也可以改为使用plot(df, x=Symbol(raw"Annual Income (k$)"), kind="box"),因为在raw"" 字符串中不会发生插值。

【讨论】:

  • 感谢您抽出宝贵时间回答我的问题!这很有帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-01
  • 2014-09-05
  • 1970-01-01
  • 2020-07-25
  • 1970-01-01
相关资源
最近更新 更多