0

enter image description here

I have a dataframe, columns to be used are "sepal_length" and "sepal_width". I want to turn each single row into a single data point, like point1= [5.1 3.5] and point2 = [4.9 3] and so on. .to_numpy() just turns the whole 2 columns into large-sized numpy array, so it does not work for me. How can I work out?

2

1 Answer 1

0

You can simply use this:

nump_df=df.values
print(nump_df)

or

You can iterate over rows and convert each row to numpy array and append those arrays in a list. I hope the following code will help you:

point=[]
for idx, row in df.iterrows():
    p=row.to_numpy()
    point.append(p)

print(point)

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.