How to count number of columns in Spark Dataframe?
To count the number of columns, simply do:
df1.columns.size
In python, the following code worked for me:
print(len(df.columns))
data.columns accesses the list of column titles. All you have to do is count the number of items in the list. so
len(df1.columns)
works To obtain the whole data in a single variable, we do
rows = df.count()
columns = len(df.columns)
size = (rows, columns)
print(size)