Reputation: 12905
In here, i want to ask how to remove bracket of a array in python. This is my following code:
import pandas as pd
import numpy as np
df = pd.read_csv('data.csv', index_col=0, header=0)
X = np.array(df.ix[:,0:29])
Y = np.array(df.ix[:,29:30])
Y
Out[55]:
array([[ 1],
[ 2],
[ 3],
...,
[35],
[36],
[37]], dtype=int64)
The desired output is following below:
Y
Out[55]:
array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10,....])
I already tried to use np.array
, however it did not work.
Upvotes: 2
Views: 4617
Reputation: 231385
Y = df.ix[:,29:30].values.ravel()
df
is a dataframe; df.ix[:,29:30]
a slice; df.ix[].values
the values as a numpy array. Use .ravel()
(or .flatten()
) to convert it from 2d to 1d as needed.
Upvotes: 2
Reputation: 11420
Check if it works
X = np.array(df.ix[:,0:29])
Y = np.array(df.ix[:,29:30])
Y = Y[0]
Upvotes: 4