想實現(xiàn)依據(jù)不同的score1,score2..分別將分數(shù)進行排序后分別等頻分箱,每個分數(shù)等頻分5箱,并依據(jù)好壞客戶指標畫圖








data["score1均勻分箱"]=pd.qcut(data["score1"],5,labels=["a","b","c","d","e

你的命令錯誤的地方應(yīng)該是data.columns=
["td_device_proxy"]
你要把這一句刪掉
后面的命令改為
data["score1均勻分箱"]=pd.qcut(data["td_device_proxy"],5,labels=["a","b","c","d","e

你試一下下面的代碼
import pandas as pd
import numpy as np
#模擬一些數(shù)據(jù)
data1=pd.DataFrame(np.random.random_integers(1,1000,(100,3)))
data1.columns=["x1","x2","x3"]
data1["x1均勻分箱"]=pd.qcut(data1["x1"],4,labels=["a","b","c","d"])
data1=pd.DataFrame(np.random.random_integers(1,1000,(100,3)))
data1.columns=["x1","x2","x3"]
上面這兩句的意思是導(dǎo)入數(shù)據(jù)或者生成模擬數(shù)據(jù),只要生成一個數(shù)據(jù)框?qū)ο缶托?,根?jù)你前面的截圖,你已經(jīng)有數(shù)據(jù)框了,不需要執(zhí)行這兩句。
你需要用到的是下面這句
data1["x1均勻分箱"]=pd.qcut(data1["x1"],4,labels=["a","b","c","d"])
pd.qcut是對變量進行分位數(shù)分箱,data1["x1"]是你對哪個變量進行分箱,4是分箱分成4類,labels參數(shù)設(shè)定這四類的標簽,如果不設(shè)定就會用0、1、2、3代替。