まだPysparkには比較的新しいです。私はバージョン2.1.0を使用します。 はるかに大きなデータセットでいくつかのデータを消去しようとしています。 私は、 "dropDuplicates"やサブセットやSQL関数(distinct、countなど)などのいくつかのテクニックをうまく使いました。Pysparkでdropnaでデータを消去
私は事を単純化するかもしれないと思ったdropnaに来ました。しかし、なぜ私は行3と6がまだdropnaを使用した後に存在するのか分からない。たとえば :
df = spark.createDataFrame([(1, 'Peter', 1.79, 28,'M', 'Tiler'),
(2, 'Fritz', 1.78, 45,'M', None),
(3, 'Florence', 1.75, None, None, None),
(4, 'Nicola',1.6, 33,'F', 'Dancer'),
(5, 'Gregory', 1.8, 54,'M', 'Teacher'),
(6, 'Steven', 1.82, None, 'M', None),
(7, 'Dagmar', 1.7, 42,'F', 'Nurse'),]
, ['id', 'Name', 'Height', 'Age', 'Gender', 'Occupation'])
df.show()
df.dropna(thresh=2)
df.show()
出力:
+---+--------+------+----+------+----------+
| id| Name|Height| Age|Gender|Occupation|
+---+--------+------+----+------+----------+
| 1| Peter| 1.79| 28| M| Tiler|
| 2| Fritz| 1.78| 45| M| null|
| 3|Florence| 1.75|null| null| null|
| 4| Nicola| 1.6| 33| F| Dancer|
| 5| Gregory| 1.8| 54| M| Teacher|
| 6| Steven| 1.82|null| M| null|
| 7| Dagmar| 1.7| 42| F| Nurse|
+---+--------+------+----+------+----------+
+---+--------+------+----+------+----------+
| id| Name|Height| Age|Gender|Occupation|
+---+--------+------+----+------+----------+
| 1| Peter| 1.79| 28| M| Tiler|
| 2| Fritz| 1.78| 45| M| null|
| 3|Florence| 1.75|null| null| null|
| 4| Nicola| 1.6| 33| F| Dancer|
| 5| Gregory| 1.8| 54| M| Teacher|
| 6| Steven| 1.82|null| M| null|
| 7| Dagmar| 1.7| 42| F| Nurse|
+---+--------+------+----+------+----------+
行が削除されない理由を誰かが提案してもらえますか?
pyspark examplesは、私が想定した使用法での正しいカウントを示しています。
# threshold
self.assertEqual(self.spark.createDataFrame(
[(u'Alice', None, 80.1)], schema).dropna(thresh=2).count(),
1)
self.assertEqual(self.spark.createDataFrame(
[(u'Alice', None, None)], schema).dropna(thresh=2).count(),
0)
ありがとうございました。 – alortimor