我有一个如下数据框,我想过滤Column FisherID中的每3行,然后将重复的物种放在列SpeciesName中。实际上,我可以通过使用下面的代码手动完成,但由于我有很多行,因此需要花费很多时间。所以,我想知道我们是否可以使用另一种方式,然后更快(例如滚动窗口......)。非常感谢。
我目前的代码:
site1=df.query('FisherID == [1,2,3]'); site_1=site1.groupby(["FisherID", "CountryName"])["SpeciesName"].apply(lambda x: x.drop_duplicates())
site2=df.query('FisherID == [4,5,6]'); site_2=site2.groupby(["FisherID", "CountryName"], as_index=True)["SpeciesName"].apply(lambda x: x.drop_duplicates())
这是我的数据:
FisherID CountryName SpeciesName
10 Vietnam Barbonymus altus
11 Vietnam Barbonymus gonionotus
12 Vietnam Barbonymus schwanenfeldi
7 Thailand Anguilla marmorata
8 Thailand Bagarius yarrelli
9 Thailand Bagrichthys obscurus
4 Lao Albulichthys albuloides
5 Lao Amblyrhynchichthys truncatus
6 Lao Anabas testudineus
1 Cambodia Amblyrhynchichthys truncatus
2 Cambodia Acanthopsis sp.1
3 Cambodia Achiroides melanorhynchus
4 Lao Albulichthys albuloides
5 Lao Amblyrhynchichthys truncatus
6 Lao Anabas testudineus
4 Lao Albulichthys albuloides
5 Lao Amblyrhynchichthys truncatus
6 Lao Anabas testudineus
7 Thailand Anguilla marmorata
8 Thailand Bagarius yarrelli
9 Thailand Bagrichthys obscurus
10 Vietnam Barbonymus altus
11 Vietnam Barbonymus gonionotus
12 Vietnam Barbonymus schwanenfeldi