Reputation: 3233
I am selecting row by row as follows:
for i in range(num_rows):
row = df.iloc[i]
as a result I am getting a Series object where row.index.values
contains names of df
columns.
But I wanted instead dataframe with only one row having dataframe columns in place.
When I do row.to_frame()
instead of 1x85
dataframe (1 row, 85 cols) I get 85x1
dataframe where index contains names of columns and row.columns
outputs
Int64Index([0], dtype='int64')
.
But all I want is just original data-frame columns with only one row. How do I do it?
Or how do I convert row.index
values to row.column
values and change 85x1
dimension to 1x85
Upvotes: 0
Views: 622
Reputation: 323226
You just need to adding T
row.to_frame().T
Also change your for loop with adding []
for i in range(num_rows):
row = df.iloc[[i]]
Upvotes: 2