我在蜂巢hive_tbl
中有一个表,其中有列'col_1','col_2','col_3'
。我已经在上述数据之上创建了一个数据框。
现在我正在获取使用describe()
指定的列的统计信息,我得到的结果如下。
+-------+------------------+------------------+------------------+
|summary| col1 | col2 | col3 |
+-------+------------------+------------------+------------------+
| count| 17547479| 17547479| 17547479|
| mean|2.0946498354549963| 1.474746257282603|1943.9881619448768|
| stddev|1.7921560893864912|1.2898177241581452| 40126.73218327477|
| min| 0.0| 0.0| 0.0|
| max| 99.0| 60.0| 1.6240624E8|
+-------+------------------+------------------+------------------+
以上计数给出了整个表中记录的计数。
但是我们可以在使用描述时将过滤器应用于特定列,即在获取某些列的计数时,我有一些空白/值可以忽略,例如col_1
的记录计数值为549023
。
我们能得到以下结果吗?
+-------+------------------+------------------+------------------+
|summary| col1 | col2 | col3 |
+-------+------------------+------------------+------------------+
| count| 549023 | 854049| 17547479|
| mean|2.0946498354549963| 1.474746257282603|1943.9881619448768|
| stddev|1.7921560893864912|1.2898177241581452| 40126.73218327477|
| min| 0.0| 0.0| 0.0|
| max| 99.0| 60.0| 1.6240624E8|
+-------+------------------+------------------+------------------+
答案 0 :(得分:0)
您可以使用df.na().drop()
来丢弃特定列中包含NaN
或NULL
值的任何行。例如,
df.na.drop(subset=["col1"])
将删除col1
为NaN
或NULL
的所有行。最后,您现在可以describe()
过滤的数据框:
filtered_df = df.na.drop(subset=["col1"])
filtered_df.describe()