UPDATE: more general solution for showing N largest values for all columns:
In [393]: df
Out[393]:
a b c
0 2 9 9
1 4 8 0
2 8 6 3
3 0 8 3
4 3 6 0
In [394]: N = 2
...: pd.DataFrame([df[c].nlargest(N).values.tolist() for c in df.columns],
...: index=df.columns,
...: columns=['{}_largest'.format(i) for i in range(1, N+1)]).T
...:
Out[394]:
a b c
1_largest 8 9 9
2_largest 4 8 3
In [395]: N = 3
...: pd.DataFrame([df[c].nlargest(N).values.tolist() for c in df.columns],
...: index=df.columns,
...: columns=['{}_largest'.format(i) for i in range(1, N+1)]).T
...:
Out[395]:
a b c
1_largest 8 9 9
2_largest 4 8 3
3_largest 3 8 3
OLD answer:
I assume that you want to have 2 (or n) largest values for a single column (as you used usecols=[1]
):
In [279]: df
Out[279]:
a b c
0 1 0 2
1 0 7 7
2 7 7 9
3 5 1 6
4 7 0 3
5 4 0 4
6 0 6 1
7 8 3 6
8 2 8 8
9 2 9 2
In [280]: df['a'].nlargest(2)
Out[280]:
7 8
2 7
Name: a, dtype: int32
NOTE: if your CSV file doesn't have labels (column names), you can read it this way (assuming that you want to read only second (1
) and fourth (3
) columns from the CSV file):
df = pd.read_csv(r'/path/to/file.csv', sep=',', usecols=[1,3],
header=None, names=['col1','col2'])