拆分具有多个标签的数据框
Splitting a dataframe with many labels
我正在尝试按不同的标签拆分我的数据,如下所示:
dfa = df_a[((df_a['label'] == 0) | (df_a['label'] == 15) | (df_a['label'] == 16))]
这适用于少量数字。但是,我想为许多值执行此操作。
例如:
to_train = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,17, 18, 19, 20) # this can change
dfb = [i for i in to_train if df_b['label']==i] # ValueError
出现错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我已阅读 并出现此错误,但我已经在使用按位运算符,它们没有解决我所理解的许多条件。
如何根据 tuple/list/etc 中的内容拆分数据框?
to_train = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,17, 18, 19, 20)
dfb = dfa[df_a['label'].isin(to_train)]
我正在尝试按不同的标签拆分我的数据,如下所示:
dfa = df_a[((df_a['label'] == 0) | (df_a['label'] == 15) | (df_a['label'] == 16))]
这适用于少量数字。但是,我想为许多值执行此操作。 例如:
to_train = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,17, 18, 19, 20) # this can change
dfb = [i for i in to_train if df_b['label']==i] # ValueError
出现错误:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我已阅读
如何根据 tuple/list/etc 中的内容拆分数据框?
to_train = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,17, 18, 19, 20)
dfb = dfa[df_a['label'].isin(to_train)]