程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

When pandas processes dataframe and series, it takes a column of data without column name

編輯:Python

Search the Internet for many answers you don't want , Grope to meet their own requirements , Write and share , Easy to remember later .

The origin of the problem : I want to use seanborn Of kdeplot drawing ,kdeplot The first parameter needs to be a one-dimensional array .

What I first introduced was Dataframe Class variables , This Dataframe Class variables are used Dataframe[[' Name ']] obtain , And then they report iloc giving 'IndexError: single positional indexer is out-of-bounds' This mistake .

Then I go through pandas.Dataframe.values The value of this column is converted to a numpy Two dimensional array of , Almost like this , as follows :

Then go ahead and deal with df.values.flatten() Into an array , Grow into the following :

This is the time to meet my requirements .

 

 


Add up :

You can also use the variable name directly ds= Dataframe[' Name ’] Get a column data without column name directly , This is the time ds For one Series object


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved