import pandas as pd
# 考察padans的一些位置上的基本操作,以及lambda对于单列和多列的操作
# 1.lambda表达式
# 1.1 dataframe对【单列操作】
data['label'] = data['score'].apply(lambda x: 1 if x>=1.0 else 0)
# 1.2 dataframe操作某列,对【多列操作】
data['score'] = data.apply(lambda x: float(x['stay_seconds'])/float(x['total_timelen']), axis=1)
# 2.获取dataframe的某列
# 2.1 index方式获取某列的特定行的index
data.index[data['item_id'] == 8712321323].tolist
输出:
[4472]
# 2.2 loc获取某列特定行的值
data.loc[data['item_id'] == 33432424324]
输出:
user_id item_id score
4472 0000255ddda8acde93412e14a3e17c1f 8742309109 1.270492
# 2.3 iloc获取某列特定行index的值
data.iloc[4472]
输出:
user_id 0000255ddda8acde93412e14a3e17c1f
item_id 8742309109
score 1.27049
Name: 4472, dtype: object