delete names columns from dataframe

delete names columns from dataframe



I crate a dataframe from iris.csv file :



raw_data = pd.read_csv("iris.csv", header=0)



raw_data :


raw_data


Species Sepal.Length Sepal.Width Petal.Length Petal.Width
0 setosa 5.1 3.5 1.4 0.2
1 setosa 4.9 3.0 1.4 0.2
2 setosa 4.7 3.2 1.3 0.2
3 setosa 4.6 3.1 1.5 0.2
4 setosa 5.0 3.6 1.4 0.2
5 setosa 5.4 3.9 1.7 0.4
6 setosa 4.6 3.4 1.4 0.3
7 setosa 5.0 3.4 1.5 0.2
8 setosa 4.4 2.9 1.4 0.2



Then I extract the first column in a data frame ;


train_y = raw_data.ix[:,0]



train_y :


train_y


0 setosa
1 setosa
2 setosa
3 setosa
4 setosa
5 setosa
6 setosa
7 setosa
8 setosa
9 setosa
10 setosa



But when I try to extract the train_X composed from other columns :


train_X = raw_data.ix[:,1:]



I get columns names too
Is there any way to delete nams columns from train_X



thanks






did you mean you want to get rid of Sepal.Length Sepal.Width Petal.Length Petal.Width ?

– Bryan
Sep 9 '18 at 9:37


Sepal.Length Sepal.Width Petal.Length Petal.Width






yes this what i am looking for

– Nasri
Sep 9 '18 at 9:53






I think you want to extract values, hence can use this raw_data.ix[:,1:].values more details, pandas.pydata.org/pandas-docs/stable/generated/…

– Bryan
Sep 9 '18 at 10:23



raw_data.ix[:,1:].values




1 Answer
1



To get the data, try this:


train_X = raw_data.iloc[:, 1:]






hello, same thing

– Nasri
Sep 9 '18 at 9:39






You could try to import the data without the column names: raw_data = pd.read_csv("iris.csv", header=False)

– Ale
Sep 9 '18 at 9:43


raw_data = pd.read_csv("iris.csv", header=False)






It not true : got this error : TypeError: Passing a bool to header is invalid. Use header=None for no header or header=int or list-like of ints to specify the row(s) making up the column names

– Nasri
Sep 9 '18 at 9:52



Thanks for contributing an answer to Stack Overflow!



But avoid …



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Malaysia to Papua New Guinea by motorcycle?

.name

List of Bhojpuri films