Numpy array from pandas dataframe
Not entirely sure what you mean by &quot;numpy vectors&quot; but am assuming the question is why each of these methods return essentially (almost but not quite) the same output...
Reference: pandas docs.
df['name'].values is a &quot;Series corresponding to colname&quot;. In other words, you're just calling the data from that column and putting the in an array by calling .values.
.iloc is a &quot;Purely integer-location based indexing for selection by position&quot;. Same as above but you're calling the indexed location of the column where df.iloc[:, 1] is df.iloc[all rows, col 2]. Probably an easier method to call multiple consecutive columns in a DataFrame then writing out each individual column name.
df.iloc[:,1:2].values &lt;-- creates an array of arrays where the main array is the column that you called (col2) and each row values is contained in a subarray. This is--I think-- because you're slicing the dataframe between column index locations 1 and 2 (rather than just calling loc 1 like above). This would mean that each row is being called individually so that a new array is created for each row that exists between column index locations 1 and 2 (which is the 'parent' array).