You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何列出分类列的唯一值?已通过df.nunique()获取数量需具体值

获取DataFrame分类列的唯一值列表

要直接提取DataFrame中某一列的所有唯一值,不用逐行查看,用unique()方法就能实现:

假设你的DataFrame名为df,目标列是"channel used",执行以下代码:

unique_channels = df["channel used"].unique()

执行后unique_channels会返回该列的唯一值数组,示例结果为array(['youtube', 'facebook', 'instagram', 'email'], dtype=object)。

如果想要转换成逗号分隔的字符串格式(如你需要的youtube、facebook、instagram、email),可以用:

formatted_channels = "、".join(df["channel used"].unique())
print(formatted_channels)

运行后就能直接得到目标格式的输出。

内容的提问来源于stack exchange,提问作者Chisom Eva

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 12:19:49