pandas怎样在不知道列名的情况下删除第一列?

pandas怎样在不知道列名的情况下删除第一列?

没找到怎样不通过列名来删除一列。
谢谢。


回答:

df.drop可以指定序号。
也可以通过df.columns[序号]得到列名再去删除。

DataFrame.drop(labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')

Drop specified labels from rows or columns.

Remove rows or columns by specifying label names and corresponding axis, or by specifying directly index or column names. When using a multi-index, labels on different levels can be removed by specifying the level.

Parameters

labels

single label or list-like

Index or column labels to drop.

axis

{0 or ‘index’, 1 or ‘columns’}, default 0

Whether to drop labels from the index (0 or ‘index’) or columns (1 or ‘columns’).

index

single label or list-like

Alternative to specifying axis (labels, axis=0 is equivalent to index=labels).

columns

single label or list-like

Alternative to specifying axis (labels, axis=1 is equivalent to columns=labels).

level

int or level name, optional

For MultiIndex, level from which the labels will be removed.

inplace

bool, default False

If False, return a copy. Otherwise, do operation inplace and return None.

以上是 pandas怎样在不知道列名的情况下删除第一列? 的全部内容, 来源链接: utcz.com/a/164313.html

回到顶部