PySpark---SparkSQL中的DataFrame(二)

本文详细介绍了PySpark DataFrame中的关键操作,包括使用colRegex选择列,collect获取所有数据,columns获取列名,count计算行数,cov计算协方差,创建临时表,describe进行统计描述,distinct去重,drop删除列,dropDuplicates删除重复行,dropna处理缺失值,dtypes查看数据类型,以及fillna填充空值。这些操作对于理解和处理SparkSQL中的DataFrame至关重要。
摘要由CSDN通过智能技术生成

1.colRegex(colName):

"""
Selects column based on the column name specified as a regex and returns it
as :class:`Column`.
"""

用正则表达式的方式返回我们想要的列。

df.show()
# 这里注意`的使用
df.select(df.colRegex("`(grade)+.+`")).show()

上面的(grade)是一个整体,“."表示任意字符,”+“表示前面出现的任意字符出现一次以上,既有一个以上的任意字符。

2.collect()

"""Returns all the records as a list of :class:`Row`."""

返回DataFrame中的所有数据,注意数据量大了容易造成Driver节点内存溢出!

data = df.collect()
for i in data:
    print(i)

3.columns

"""Returns all column names as a list."""

以列表的形式返回DataFrame的所有列名,这个方法是@property

print(df.columns)

4.count()

"""Returns the number of rows in this :class:`DataFrame`."&#
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值