【发布时间】:2020-11-27 12:16:27
【问题描述】:
df fruit year sale important
0 apple 2010
1 apple 2011
2 apple 2012
3 apple 2013
4 apple 2014 True Yes
5 apple 2015 True
6 apple 2017 True
7 apple 2018 True
7 apple 2019
8 apple 2020 True Yes
9 banana 2010
...
如何生成“重要”列?
是的,如果每个水果: (1) 当年有销售, (2) 前一年没有销售,并且 (3) 该年与上一个“重要”年之间至少有 3 年的差距。
【问题讨论】:
-
你能提供数据作为字典吗
-
我尝试了 df.to_dict() 但似乎无法正常工作
-
@asd 每个
fruit的所有年份是否都按顺序存在? -
是的,df 是按水果和年份排序的(即从旧年份到最近年份)
标签: python python-3.x pandas dataframe pandas-groupby