У меня есть следующая таблица:
+----------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+
| _created| _updated| name| description| indication| name| patents_patent|
+----------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+
|2005-06-13|2016-08-17| Lepirudin|Lepirudin is iden...|For the treatment...| Lepirudin|{"data" : [{"coun...|
|2005-06-13|2017-04-27| Cetuximab|Cetuximab is an e...|Cetuximab, used i...| Cetuximab|{"data" : [{"coun...|
|2005-06-13|2017-06-14| Dornase alfa|Dornase alfa is a...|Used as adjunct t...| Dornase alfa|{"data" : [{"coun...|
|2005-06-13|2016-08-17| Denileukin diftitox|A recombinant DNA...|For treatment of ...| Denileukin diftitox| NULL|
|2005-06-13|2017-03-10| Etanercept|Dimeric fusion pr...|Etanercept is ind...| Etanercept|{"data" : [{"coun...|
|2005-06-13|2017-07-06| Bivalirudin|Bivalirudin is a ...|For treatment of ...| Bivalirudin|{"data" : [{"coun...|
|2005-06-13|2017-07-05| Leuprolide|Leuprolide belong...|For treatment of ...| Leuprolide|{"data" : [{"coun...|
|2005-06-13|2017-06-16|Peginterferon alf...|Peginterferon alf...|Peginterferon alf...|Peginterferon alf...|{"data" : [{"coun...|
|2005-06-13|2017-06-08| Alteplase|Human tissue plas...|For management of...| Alteplase| NULL|
|2005-06-13|2016-12-08| Sermorelin|Sermorelin acetat...|For the treatment...| Sermorelin| NULL|
|2005-06-13|2016-08-17| Interferon alfa-n1|Purified, natural...|For treatment of ...| Interferon alfa-n1| NULL|
В идеале мне нужно будет вывести 2 таблицы:
table_one Я отфильтрую таблицу, в которой патент_патент не равен NULL, и заменю строки в патенте-патенте на 1:
+----------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+
| _created| _updated| name| description| indication| name| patents_patent|
+----------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+
|2005-06-13|2016-08-17| Lepirudin|Lepirudin is iden...|For the treatment...| Lepirudin|1|
|2005-06-13|2017-04-27| Cetuximab|Cetuximab is an e...|Cetuximab, used i...| Cetuximab|1|
|2005-06-13|2017-06-14| Dornase alfa|Dornase alfa is a...|Used as adjunct t...| Dornase alfa|1|
|2005-06-13|2017-03-10| Etanercept|Dimeric fusion pr...|Etanercept is ind...| Etanercept|1|
|2005-06-13|2017-07-06| Bivalirudin|Bivalirudin is a ...|For treatment of ...| Bivalirudin|1|
|2005-06-13|2017-07-05| Leuprolide|Leuprolide belong...|For treatment of ...| Leuprolide|1|
|2005-06-13|2017-06-16|Peginterferon alf...|Peginterferon alf...|Peginterferon alf...|Peginterferon alf...|1|
|
table_two = отфильтровать таблицу, в которой патент_патента равен нулю, и заменить ноль на 0
+----------+----------+--------------------+--------------------+--------------------+--------------------+--------------------+
| _created| _updated| name| description| indication| name| patents_patent|
+----------+----------+--------------------+--------------------+--------------------+--------------------+------------------
|2005-06-13|2016-08-17| Denileukin diftitox|A recombinant DNA...|For treatment of ...| Denileukin diftitox| 0|
|2005-06-13|2017-06-08| Alteplase|Human tissue plas...|For management of...| Alteplase| 0|
|2005-06-13|2016-12-08| Sermorelin|Sermorelin acetat...|For the treatment...| Sermorelin| 0|
|2005-06-13|2016-08-17| Interferon alfa-n1|Purified, natural...|For treatment of ...| Interferon alfa-n1| 0|
Я пробовал это:
Я пробовал это:
from pyspark.sql.functions import col, expr, when
data = table.where(col("patents_patent").isNull())
data = table.filter("patents_patent is not NULL")
Результаты неправильные или пустые:!
root
|-- _created: string (nullable = true)
|-- _updated: string (nullable = true)
|-- name: string (nullable = true)
|-- description: string (nullable = true)
|-- indication: string (nullable = true)
|-- patents_patent: string (nullable = true)
Спасибо за помощь !
Я обновил вопрос
Какой тип patents_patent вы можете поделиться схемой?
значения на самом деле null или это строка "NULL", как вы показали в своем примере?
-я строка имеет значение NULL, как показано в примере
Хорошо, тогда попробуйте: data = table.where(col("patents_patent") == "NULL").withColumn("patents_patent", "0") - поскольку столбец является строковым столбцом, вы должны использовать строку 0 в качестве значения замены.
спасибо, это не работает






table_one I will filter out table where patent_patent is not NULL and replace the strings in patent-patent by 1:
В первом случае вам следует сделать
data_not_null = table.filter((table['patents_patent'] != "NULL")).withColumn('patents_patent', f.lit("1"))
table_two = filter out table where patents_patent is null and replace null by 0
Для второго вы должны сделать следующее
data_null = table.where(f.col("patents_patent").isNull() | (table['patents_patent'] == "NULL")).withColumn('patents_patent', f.lit("0"))
и для них я импортирую как
from pyspark.sql import functions as f
и конечно же f.col("patents_patent") и table['patents_patent'] означают одно и то же
Можете показать, что пробовали и в чем проблема?