小编Dil*_*ula的帖子

查询panda df以过滤列不是Nan的行

我是 python 的新手并使用 Pandas。

我想查询一个数据框并过滤其中一列不是的行NaN

我试过了:

a=dictionarydf.label.isnull()
Run Code Online (Sandbox Code Playgroud)

但是 a 填充了trueor false。试过这个

dictionarydf.query(dictionarydf.label.isnull())
Run Code Online (Sandbox Code Playgroud)

但如我所料,出现了错误

样本数据:

      reference_word         all_matching_words  label review
0           account             fees - account    NaN      N
1           account           mobile - account    NaN      N
2           account          monthly - account    NaN      N
3    administration  delivery - administration    NaN      N
4    administration      fund - administration    NaN      N
5           advisor             fees - advisor    NaN      N
6           advisor          optimum - advisor    NaN      N
7           advisor              sub - advisor    NaN      N
8 …
Run Code Online (Sandbox Code Playgroud)

python indexing nan pandas pandasql

5
推荐指数
1
解决办法
3425
查看次数

使用spark在Scala中将数据帧拆分为两个或多个数据帧

我有一个包含 200 万条记录的数据集。我想把它分成两个相等的一半。我没有任何带有序列号的列,因此我可以对其应用 where 条件并将其拆分为 2。这也可能不是正确的方法,但我想要做的就是将数据帧拆分为 2 个一半

我正在使用的示例代码:

var invoiceData = sc.textFile("/Scala/InvoiceLine.csv");
def removeheader (x : RDD[String]): RDD[String] = {
  x.mapPartitionsWithIndex((idx, lines) => {
    if (idx == 0) {
      lines.drop(1)
    }
    lines
  })
}
var invoiceWithoutHeader = removeheader(invoiceData);
var invoiceSchemaString = invoiceData.first().toUpperCase().split(",").map(_.trim());
var invoiceSchema = StructType(invoiceSchemaString.map(fieldName => StructField(fieldName, StringType, true)))
var invoiceRowRDD = invoiceWithoutHeader.map(y => {
  var parser = new CSVParser(',');
  parser.parseLine(y)
}).map { x => Row.fromSeq(x) } 
var invoiceDF = sqlContext.applySchema(invoiceRowRDD, invoiceSchema);
Run Code Online (Sandbox Code Playgroud)

现在我想将invoiceDF分成2部分,每部分100万,因为我是初学者,代码可能效率不高,对不起。

提前致谢 :)

scala apache-spark

1
推荐指数
1
解决办法
5482
查看次数

如何将常量整数值添加到整数列?

我有一个包含 3 列的数据框,其中一列是整数。我想给它添加一个整数值。

id person age
1  person1 4
2  person4 5
3  person3 7
Run Code Online (Sandbox Code Playgroud)

我想给他们的年龄加上一个常数 20,这样他们的年龄将分别是 24,25 和 27。

scala apache-spark apache-spark-sql

-1
推荐指数
1
解决办法
1447
查看次数