在Julia中,DataFrame类型允许您将其视为数组进行访问,因此可以通过索引方式删除列:
df = df[:,[1:2,4:end]] # remove column 3
这种方法的问题在于我通常只知道列的名称,而不知道它在表中的列索引。
是否有一种内置的方法可以按名称删除列?
或者,有没有比这更好的方法?
colind = findfirst(names(df), colsymbol)
df = df[:,[1:colind-1,colind+1:end]]
上述方法容易出现故障;存在一些极端情况(单列、第一列、最后一列、符号不在表格中等)。
谢谢
columnindex(df, :your_column_symbol)
访问列索引。 - Merlin