import numpy as np
import pandas as pd
data = np.array([[1,2,3,4,5], [2,2,2,2,2], [3,3,3,3,3], [4,4,3,4,4], [7,2,3,4,5]])
columns = ["one", "two", "three", "four", "five"]
dframe_main = pd.DataFrame(data=data, columns=columns)
print "All columns:"
print dframe_main
del dframe_main[dframe_main.columns[0]] # get rid of the first column
print "All columns except the first:"
print dframe_main
输出为:
All columns:
one two three four five
0 1 2 3 4 5
1 2 2 2 2 2
2 3 3 3 3 3
3 4 4 3 4 4
4 5 2 3 4 5
All columns except the first:
two three four five
0 2 3 4 5
1 2 2 2 2
2 3 3 3 3
3 4 3 4 4
4 2 3 4 5
你看完后把这列删掉就够了吗?这在功能上与从读取中排除第一列相同。以下是一个玩具示例:
输出为:
我建议使用usecols参数:
假设文件有5列:
相关问题 更多 >
编程相关推荐