pandas 技巧

Posted pocahontas

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了pandas 技巧相关的知识,希望对你有一定的参考价值。

 

find index of top 3 largest values of each column:

 

df1.apply(lambda s: pd.Series(s.nlargest(3).index))

 

map dataframe column

df["ItemIdx"] = df["question"].map(lambda x: itemMap.get(x,np.NaN))

 

load a dictionay from a save pkl file

with open ("l.pkl","rb") as f:
    itemMap= pickle.lead(f)

 

find the startpoint of each session (after sorted):

offset = np.zeros(df["sessinId"].nunique()+1,dtype=np.int32)
offset[1:] = df.groupby(‘sessinId‘).size().cumsum()

 

以上是关于pandas 技巧的主要内容,如果未能解决你的问题,请参考以下文章