[英]Dropping the first column in Pandas
command description
0 aaa ikegroup WORD Name of the IKE group
1 aaa ikegroup <cr>
0 aaa locald trace Show trace data for the locald component(cisco...
0 aaa login trace Show trace data for login sub system
0 aaa password-policy statistics Show statistics related to password policy
1 aaa password-policy WORD Name of the Password Policy
以上是我的数据框的外观。 我想摆脱具有数字的第一列,而不是command
列。 但是,当我这样做时:
df2 = df.drop([df.columns[0]], axis='columns')
这将删除command
列,而不是带有索引的列。
如何删除第一个?
IIUC,您的第一列就是您的索引。 您可以随时将其隐藏在笔记本中
df.style.hide_index()
但不确定是否会带来很多价值。
如果要写入文件(例如to_csv
),则可以始终将index=False
设置为忽略它,例如
df.to_csv('file.csv', index=False)
您还可以将任何列分配为索引:
df.set_index('command', inplace=True)
其他有用的命令:
# reset the index
df.reset_index(inplace=True, drop=True)
# sort by index
df.sort_index(inplace=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.