计算一行中不同变量的数量
我有一个关于清理数据/检查观察结果的问题。由于隐私问题,我无法分享完整的代码或数据。我可以用一个例子来说明我想要实现的目标。假设这是我的数据集。
个体 | 年份 |
---|---|
101 | 2018 |
101 | 2019 |
102 | 2019 |
103 | 2019 |
104 | 2017 |
104 | 2018 |
104 | 2019 |
假设我想计算这个数据集中不同个体的数量。那么,在本例中,它将是 4('101'、'102'、'103'、'104')。但是,我以一种非常广泛的方式来理解这一点。有没有一种简单的方法来检查总数据集有多少个人?
希望有人可以提供帮助:)我认为应该有一个简单的解决方案,但到目前为止谷歌搜索还没有帮助。
I have a question regarding cleaning data/checking observations. Due to privacy issues, I cannot share the full code or data. I can illustrate what I want to achieve with an example. Suppose this is my dataset.
Individual | Year |
---|---|
101 | 2018 |
101 | 2019 |
102 | 2019 |
103 | 2019 |
104 | 2017 |
104 | 2018 |
104 | 2019 |
And suppose I want to count the number of different individuals in this dataset. Then, in this case, it would be 4 ('101', '102', '103', '104'). But, I have this in a very extended way. Is there an easy way to check how many individuals the total dataset has?
Hopefully, somebody can help :) I think there should be an easy solution to this, but googling hasn't helped so far.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是您的示例数据:
如下所示:
要计算列中唯一值的数量,您可以使用以下代码:
输出为:
本例中的输出为 4。
Here is your example data:
Looks like this:
To count the number of unique values in a column, you can use the following code:
The output is:
The output is in this case 4.