This selects the second and fourth columns (since Python uses 0-based indexing):
In [272]: df.iloc[:,(1,3)] Out[272]: value f 0 975 5 1 976 4 2 977 1 3 978 0 4 979 0 [5 rows x 2 columns]
df.ix can choose a location or label. df.iloc always chooses a location. When indexing by location, use df.iloc to more clearly indicate your intention. It is also slightly faster since Pandas does not need to check if your index uses tags.
Another possibility is to use the usecols parameter:
data = pandas.read_csv("ThisFile.csv", usecols=[1,3])
This will load only the second and fourth columns in the data DataFrame.
unutbu
source share