【发布时间】:2019-05-23 15:19:51
【问题描述】:
我希望创建一个新的数据帧,以过滤掉先前数据帧中的冗余信息。原始数据框是通过查看许多文件夹并提供一列元素创建的,每个元素包含访问每个文件的完整路径的字符串。每个文件根据相应的测试文件夹中的试验编号和分数命名。我需要删除每次试验的分数为 100 的所有重复,但是每次试验的第一个 100 分数必须保留。
对于 python Pandas,我知道使用 df[df[col_header].str.contains('text')] 专门过滤掉需要的内容,并将“~”用作布尔 NOT。
带有冗余分数的未过滤数据框列看起来像这样
\\desktop\Test_Scores\test1\trial1-98
\\desktop\Test_Scores\test1\trial2-100
\\desktop\Test_Scores\test1\trial3-100 #<- must remove
\\desktop\Test_Scores\test2\trial1-95
\\desktop\Test_Scores\test2\trial2-100
\\desktop\Test_Scores\test2\trial3-100 #<- must remove
\\desktop\Test_Scores\test2\trial3-100 #<- must remove
.
.
.
n
使用一些代码作为过滤器后的预期结果将是一个看起来像这样的数据帧
\\desktop\Test_Scores\test1\trial1-98
\\desktop\Test_Scores\test1\trial2-100
\\desktop\Test_Scores\test2\trial1-95
\\desktop\Test_Scores\test2\trial2-100
.
.
.
.
n
【问题讨论】:
标签: python pandas python-2.7 dataframe