df only take 2 columns 1

df only take 2 columns

df1 = df[['a', 'b']]

Here is what the above code is Doing:
1. df[[‘a’, ‘b’]] is a DataFrame with columns ‘a’ and ‘b’
2. df[[‘a’, ‘b’]].values is a numpy array with the values of the columns ‘a’ and ‘b’
3. df[[‘a’, ‘b’]].values.T is a numpy array with the values of the columns ‘a’ and ‘b’ transposed
4. df[[‘a’, ‘b’]].values.T.tolist() is a list of lists with the values of the columns ‘a’ and ‘b’ transposed
5. df[[‘a’, ‘b’]].values.T.tolist()[0] is a list with the values of the column ‘a’
6. df[[‘a’, ‘b’]].values.T.tolist()[1] is a list with the values of the column ‘b’
7. df[[‘a’, ‘b’]].values.T.tolist()[0][0] is the value of the first row of the column ‘a’
8. df[[‘a’, ‘b’]].values.T.tolist()[1][0] is the value of the first row of the column ‘b’

Similar Posts