嗨,我有以下问题:
numeric.registerTempTable("numeric").
Run Code Online (Sandbox Code Playgroud)
我要过滤的所有值都是文字空字符串,而不是N/A或Null值.
我试过这三个选项:
numeric_filtered = numeric.filter(numeric['LOW'] != 'null').filter(numeric['HIGH'] != 'null').filter(numeric['NORMAL'] != 'null')
numeric_filtered = numeric.filter(numeric['LOW'] != 'null' AND numeric['HIGH'] != 'null' AND numeric['NORMAL'] != 'null')
sqlContext.sql("SELECT * from numeric WHERE LOW != 'null' AND HIGH != 'null' AND NORMAL != 'null'")
不幸的是,numeric_filtered总是空的.我检查并且数字具有应根据这些条件过滤的数据.
以下是一些示例值:
低高正常
3.5 5.0 null
2.0 14.0 null
null 38.0 null
null null null
1.0 null 4.0
我.csv
有几列,我希望'n'
在使用spark.read.csv()
函数将此文件导入数据帧时跳过 4 行(或一般情况下)。我有一个.csv
这样的文件 -
ID;Name;Revenue
Identifier;Customer Name;Euros
cust_ID;cust_name;€
ID132;XYZ Ltd;2825
ID150;ABC Ltd;1849
Run Code Online (Sandbox Code Playgroud)
在普通的 Python 中,使用read_csv()
函数时,很简单,可以使用以下skiprow=n
选项来完成-
import pandas as pd
df=pd.read_csv('filename.csv',sep=';',skiprows=3) # Since we wish to skip top 3 lines
Run Code Online (Sandbox Code Playgroud)
使用 PySpark,我按如下方式导入这个 .csv 文件 -
df=spark.read.csv("filename.csv",sep=';')
This imports the file as -
ID |Name |Revenue
Identifier |Customer Name|Euros
cust_ID |cust_name |€
ID132 |XYZ Ltd |2825
ID150 |ABC Ltd 1849
Run Code Online (Sandbox Code Playgroud)
这是不正确的,因为我希望忽略前三行。我不能使用选项,'header=True'
因为它只会排除第一行。可以使用'comment='
选项,但为此需要行以特定字符开头,而我的文件并非如此。我在文档中找不到任何内容。有没有办法做到这一点?
Pyspark 是全新的,我正在重构一些 R 代码,这些代码开始失去正确扩展的能力。我返回一个数据帧,其中包含许多带有数值的列,并且我尝试使用多个复合条件将此结果集过滤为一个新的、更小的结果集。
from pyspark.sql import functions as f
matches = df.filter(f.when('df.business') >=0.9 & (f.when('df.city') == 1.0) & (f.when('street') >= 0.7)) |
(f.when('df.phone') == 1) & (f.when('df.firstname') == 1) & (f.when('df.street') == 1) & (f.when('df.city' == 1)) |
(f.when('df.business') >=0.9) & (f.when('df.street') >=0.9) & (f.when('df.city')) == 1))) |
(f.when('df.phone') == 1) & (f.when('df.street') == 1) & (f.when('df.city')) == 1))) |
(f.when('df.lastname') >=0.9) & (f.when('df.phone') == 1) & (f.when('df.business')) >=0.9 & (f.when('df.city') == 1))) |
(f.when('df.phone') == 1 & (f.when('df.street') …
Run Code Online (Sandbox Code Playgroud)