朱莉娅(Julia)中有类似物吗?

发布于 2025-02-12 04:06:48 字数 115 浏览 1 评论 0原文

我在DataFrame中有一个整数列。如何将其值转换为朱莉娅的字符串? 在r中可以简单地写:

mutate(column2 = as.factor(column1))

I have an integer column in dataframe. How can I convert its values into string in Julia?
In R a can simply write:

mutate(column2 = as.factor(column1))

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

z祗昰~ 2025-02-19 04:06:48

在Julia中:

julia> using DataFramesMeta, CategoricalArrays

julia> df = DataFrame(a=1:3, b='a':'c')
3×2 DataFrame
 Row │ a      b
     │ Int64  Char
─────┼─────────────
   1 │     1  a
   2 │     2  b
   3 │     3  c

julia> @transform!(df, :b = categorical(:b))
3×2 DataFrame
 Row │ a      b
     │ Int64  Cat…
─────┼─────────────
   1 │     1  a
   2 │     2  b
   3 │     3  c

@transform如果您想要一个新的数据框架。同样,目标列名称可能是不同的,例如:b_categorical = apcatorical(:b)

In Julia:

julia> using DataFramesMeta, CategoricalArrays

julia> df = DataFrame(a=1:3, b='a':'c')
3×2 DataFrame
 Row │ a      b
     │ Int64  Char
─────┼─────────────
   1 │     1  a
   2 │     2  b
   3 │     3  c

julia> @transform!(df, :b = categorical(:b))
3×2 DataFrame
 Row │ a      b
     │ Int64  Cat…
─────┼─────────────
   1 │     1  a
   2 │     2  b
   3 │     3  c

or @transform if you want a new data frame. Also target column name can be different e.g. :b_categorical = categorical(:b).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文