【发布时间】:2019-07-04 12:23:42
【问题描述】:
我在下面有这个 DataFrame:
Ref ° | Indice_1 | Indice_2 | 1 | 2 | indice_from | indice_from | indice_to | indice_to
---------------------------------------------------------------------------------------------------------------------------------------------
1 | 19 | 37.1 | 32 | 62 | ["20031,10031"] | ["13,11/12"] | ["40062,30062"] | ["14A,14"]
---------------------------------------------------------------------------------------------------------------------------------------------
2 | 19 | 37.1 | 44 | 12 | ["40062,30062"] | ["13,11/12"] | ["40062,30062"] | ["14A,14"]
---------------------------------------------------------------------------------------------------------------------------------------------
3 | 19 | 37.1 | 22 | 64 | ["20031,10031"] | ["13,11/12"] | ["20031,10031"] | ["13,11/12"]
---------------------------------------------------------------------------------------------------------------------------------------------
4 | 19 | 37.1 | 32 | 98 | ["20032,10032"] | ["13,11/12"] | ["40062,30062"] | ["13,11/12"]
我想按列 indice_from、indice_from、indice_to 和 indice_to 的值进行排序,并且我不应该触及 DataFrame 的其余列。 知道 2 列 indice_from 和 indice_to 有时包含一个数字 + 字母,例如:["14,14A"] 如果我有一个像 ["14,14A"] 这样的例子,我总是应该有相同的结构,例如,如果我有:
数字15,第二个值应该是15+字母,15
新数据框:
Ref ° | Indice_1 | Indice_2 | 1 | 2 | indice_from | indice_from | indice_to | indice_to
---------------------------------------------------------------------------------------------------------------------------------------------
1 | 19 | 37.1 | 32 | 62 | ["10031,20031"] | ["11/12,13"] | ["30062,40062"] | ["14,14A"]
---------------------------------------------------------------------------------------------------------------------------------------------
2 | 19 | 37.1 | 44 | 12 | ["30062,40062"] | ["11/12,13"] | ["30062,40062"] | ["14,14A"]
---------------------------------------------------------------------------------------------------------------------------------------------
3 | 19 | 37.1 | 22 | 64 | ["10031,20031"] | ["11/12,13"] | ["10031,20031"] | ["11/12,13"]
---------------------------------------------------------------------------------------------------------------------------------------------
4 | 19 | 37.1 | 32 | 98 | ["10031,20031"] | ["11/12,13"] | ["30062,40062"] | ["11/12,13"]
请有人帮助我如何对列 indice_from、indice_from、indice_to 和 indice_to 的值进行排序,以获得像上面第二个 df 这样的新数据框? 谢谢
【问题讨论】:
-
你能显示你的数据框的架构吗?
df.printSchema -
您将数字排序为数字还是字符串?作为数字:14 ,作为字符串:'100'
-
@Steven 列类型是字符串数组
-
我不明白你的第二条评论
-
那我们会遇到问题,因为这是您请求的关键信息