我有一个数据框:
df = pd.DataFrame({'start': ['2020-08-01', '2020-08-02', '2020-08-03', '2020-08-04', '2020-08-05', '2020-08-06', '2020-08-07', '2020-08-08'],
'end': ['2020-08-03', '', '', '2020-08-06', '', '2020-08-08', '', ''],
'score': [74, 81, 38, 49, 79, 17, 53, 69]})
df
start end score
0 2020-08-01 2020-08-03 74
1 2020-08-02 81
2 2020-08-03 38
3 2020-08-04 2020-08-06 49
4 2020-08-05 79
5 2020-08-06 2020-08-08 17
6 2020-08-07 53
7 2020-08-08 69
我需要添加一个新列,其中在中找到日期1
时该行被标记为:end
start
start end score mark
0 2020-08-01 2020-08-03 74
1 2020-08-02 81
2 2020-08-03 38 1
3 2020-08-04 2020-08-06 49
4 2020-08-05 79
5 2020-08-06 2020-08-08 17 1
6 2020-08-07 53
7 2020-08-08 69 1
有什么好的pandas
解决方案?非常感谢!
df['mark']=np.where(df.start.isin(df.end),'1',' ')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句