我用Pandas读取csv文件,它是一个两列的数据帧,然后我试图转换成spark数据帧。代码是:
from pyspark.sql import SQLContext
sqlCtx = SQLContext(sc)
sdf = sqlCtx.createDataFrame(df)
数据帧:
^{pr2}$给出了:
Name Category
0 EDSJOBLIST apply at www.edsjoblist.com ['biotechnology', 'clinical', 'diagnostic', 'd...
1 Power Direct Marketing ['advertising', 'analytics', 'brand positionin...
2 CHA Hollywood Medical Center, L.P. ['general medical and surgical hospital', 'hea...
3 JING JING GOURMET [nan]
4 TRUE LIFE KINGDOM MINISTRIES ['religious organization']
5 fasterproms ['microsoft .net']
6 STEREO ZONE ['accessory', 'audio', 'car audio', 'chrome', ...
7 SAN FRANCISCO NEUROLOGICAL SOCIETY [nan]
8 Fl Advisors ['comprehensive financial planning', 'financia...
9 Fortunatus LLC ['bottle', 'bottling', 'charitable', 'dna', 'f...
10 TREADS LLC ['retail', 'wholesaling']
有人能帮我吗?在
Spark在处理
object
数据类型时会有困难。一个潜在的解决方法是先将所有内容转换为字符串:这样做的一个结果是,包括
nan
在内的所有内容都将转换为字符串。您需要注意正确处理这些转换,并将列转换为适当的类型。在例如,如果您有一个带浮点值的列
^{pr2}$"colA"
,您可以使用类似于以下的方法将字符串"nan"
转换为null
:相关问题 更多 >
编程相关推荐