如何从pyspark中的spark数据帧中提取特定值?

2024-04-24 23:31:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要从pyspark中使用sql查询提取计数。count在spark数据帧中,我想在if条件中使用count值,但无法提取该值。如何从spark数据帧中提取int值

 query = "select count(*) as count from abc where FLAG= 'C' "
    counter = sqlContext.read.format("jdbc").options(url="jdbc:mysql://localhost:3306/sample", driver="com.mysql.jdbc.Driver",
                                           query=query, user="root", password="root").load()

if counter['count']>0:
   print('hello')
else:
   print('hi')

Tags: 数据sqlifcountcountermysqlroot条件