创建样本数据
import pandas
from pandas import DataFrame
data = [["2018-03-01","2018-03-01","2018-05-01","2018-05-01","2018-06-03"],[20,30,40,10,70],
["2017-12-01","2017-12-01","2017-12-05","2017-12-06","2017-12-21"]]
sample_df = DataFrame.from_records(data).transpose()
sample_df
样本数据
0 1 2
0 2018-03-01 20 2017-12-01
1 2018-03-01 30 2017-12-01
2 2018-05-01 40 2017-12-05
3 2018-05-01 10 2017-12-06
4 2018-06-03 70 2017-12-21
在对“ 0”列进行分组并在第2列和第3列中创建值列表之后,需要创建如下所示的内容
0 1 2
2018-03-01 [20,30] [2017-12-01,2017-12-01]
2018-05-01 [40,10] [2017-12-05,2017-12-06]
2018-06-03 [70] [2017-12-21]
尝试使用apply和lambda函数,但没有成功。
任何建议。