I have this dataframe in Spark I want to count the number of available columns in it. I know how to count the number of rows in column but I want to count number of columns.
val df1 = Seq(
("spark", "scala", "2015-10-14", 10,"rahul"),
("spark", "scala", "2015-10-15", 11,"abhishek"),
("spark", "scala", "2015-10-16", 12,"Jay"),
("spark","scala",null,13,"Kiran"))
.toDF("bu_name","client_name","date","patient_id","paitent _name")
df1.show
Can anybody tell me how I can count number of column count in this dataframe? I am using the Scala language.
要计算列数,只需执行以下操作:
df1.columns.size
在python中,以下代码对我有用:
print(len(df.columns))
可变索引序列的长度也起作用。
df.columns.length
To count the columns of a Spark dataFrame:
len(df1.columns)
and to count the number of rows of a dataFrame:
df1.count()
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)
在Pyspark中,您可以只进行result.select("your column").count()
.count result.select("your column").count()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.