0

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

1 Answer 1

2

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]]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.