问题描述
最近~ 发现对series里的元素操作挺复杂的,用for loop + Series.iloc[i]会发生卡死的状况,那么,lambda是解决办法:
- error 1
ratings['timestamp'] = ratings['timestamp'].apply(ratings['timestamp'].iloc[i].strftime("%Y-%m-%d %H:%M:%S", ts) for i in range(len(ratings)))
TypeError: 'generator' object is not callable
用lambda直接apply,就相当于对每一行的每个元素,逐一apply:
ratings_sub['timestamp'] = ratings_sub['timestamp'].apply(lambda x:time.strftime('%Y/%m/%d',time.localtime(x)))