I have a dataframe with lots of columns.
I first choose only one column from the dataframe by
r_i = df.iloc[:, i: i + 1]
Then I want to turn this r_i into array simply by
np.array(r_i).
the result I want is like:
array([-1, -2, -3]). In other words, it should be array of one list.
However, it gives me array of one list which consists of sublists:
array([[-1], [-2], [-3]]).
How do I prevent this from happening?
Thank you.
df.values.flatten()
Here, df is your DataFrame.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With