我在pyspark中有以下 Dataframe
Date | Value | Date2
2019/01/10 | 9.5 | null
2019/01/10 | 9.5 | null
2019/01/11 | 4.5 | 2019/01/10
2019/01/12 | 6.7 | 2019/01/11
2019/01/12 | 6.7 | 2019/01/10
2019/01/13 | 9.2 | 2019/01/12
2019/01/14 | 13.6 | 2019/01/13
2019/01/15 | 2.7 | 2019/01/14
2019/01/16 | 7.8 | 2019/01/15
我想创建一个新列,其值是列'Value'的值,但由列Date 2索引(将其作为索引Date)。
Date | Value | Date2 | Value2
2019/01/10 | 9.5 | null | null
2019/01/10 | 9.5 | null | null
2019/01/11 | 4.5 | 2019/01/10 | 9.5
2019/01/12 | 6.7 | 2019/01/11 | 4.5
2019/01/12 | 6.7 | 2019/01/10 | 9.5
2019/01/13 | 9.2 | 2019/01/12 | 6.7
2019/01/14 | 13.6 | 2019/01/13 | 9.2
2019/01/15 | 2.7 | 2019/01/14 | 13.6
2019/01/16 | 7.8 | 2019/01/15 | 2.7
是否存在不涉及join的解决方案?
1条答案
按热度按时间nzrxty8p1#
如果不是一个大的df、susbset,则重命名列并连接。
如果df很大,尝试创建Date和Vlue列的python dict,然后Map到Date2。