Reputation: 3
I have a dataframe whoes shape is
print(trainData.shape)
(4146, 17)
What would be the reason for
c = trainData.loc[0,:]
print(c.shape)
returning
(17,)
I need the output to be a dataframe and not series
[[0]] returns (1,17)
Upvotes: 0
Views: 43
Reputation: 30032
If you want to select first row as dataframe, you can use
c = trainData.loc[[0],:]
# or
c = trainData.loc[0,:].to_frame().T
If you want to select first column as dataframe,
c = trainData.iloc[:,[0]]
# or
c = trainData.iloc[:,0].to_frame()
Upvotes: 1