删除DataFrame中的列时,我使用:
del df['column_name']
Run Code Online (Sandbox Code Playgroud)
这很有效.为什么我不能使用以下?
del df.column_name
Run Code Online (Sandbox Code Playgroud)
由于您可以访问列/系列df.column_name,我希望这可以工作.
.keep = "unused"在 R 的 dplyr 包中,使用该函数创建新列时有一个选项mutate()(相当于assign)。
给没用过的人举个例子:
> head(iris)
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
1 5.1 3.5 1.4 0.2 setosa
2 4.9 3.0 1.4 0.2 setosa
3 4.7 3.2 1.3 0.2 setosa
4 4.6 3.1 1.5 0.2 setosa
5 5.0 3.6 1.4 0.2 setosa
6 5.4 3.9 1.7 0.4 setosa
# any column used in creating `new_col` is dropped afterwards automatically
> mutate(.data = head(iris), new_col = Sepal.Length + Petal.Length * Petal.Width, .keep = …Run Code Online (Sandbox Code Playgroud) col_exclusions = ['numerator','Numerator' 'Denominator', "denominator"]
数据框
id prim_numerator sec_Numerator tern_Numerator tern_Denominator final_denominator Result
1 12 23 45 54 56 Fail
Run Code Online (Sandbox Code Playgroud)
最终输出是 id 和 Result