2

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.

0

3 Answers 3

4

Check if it works

X = np.array(df.ix[:,0:29])
Y = np.array(df.ix[:,29:30])
Y = Y[0]
Sign up to request clarification or add additional context in comments.

Comments

2
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.

Comments

1
Y = np.array(df.ix[:,29:30])
Y.shape = (len(Y))
Y

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.