I’m working with a PySpark DataFrame and trying to count the number of null values in each column. I tried the following expression:
[col(c).isNull().count() for c in df.columns]
throws error:
----> 2 [col(c).isNull().count() for c in df.columns]
TypeError: 'Column' object is not callable
On the other hand, this expression works without any issue:
[df.filter(col(c).isNull()).count() for c in df.columns]
I’m confused about why the first expression fails while the second one works. Could someone explain the difference between the two and why the error occurs in the first case?