upe*_*dra 7 python pandas pyspark pyspark-sql
我有一个包含三列的数据框,我正在尝试使用 Seaborn 库绘制线图,但它向我抛出一个错误,说'DataFrame' object has no attribute 'get'. 这是我的测试数据框
Age variable value
31 Overall 69.76751118
31 Potential 69.76751118
31 Growth 0
34 Overall 68.91176471
34 Potential 68.91176471
34 Growth 0
28 Overall 69.05803996
28 Potential 69.05803996
28 Growth 0.24643197
Run Code Online (Sandbox Code Playgroud)
这就是我在读取 csv 文件后尝试使用 seaborn 线图所做的
test = spark.read.csv("test.csv", inferSchema=True, header=True)
sns.lineplot(x = "Age", y = "value", hue = "variable", data = test)
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这个
AttributeError: 'DataFrame' object has no attribute 'get'
Run Code Online (Sandbox Code Playgroud)
但是,当我将数据框转换为 Pandas 数据框并使用完全相同的 seaborn 代码时
test_df = test.toPandas()
sns.lineplot(x = "Age", y = "value", hue = "variable", data = test_df)
Run Code Online (Sandbox Code Playgroud)
我对 Spark 数据帧做错了什么。
Spark 数据框和 Pandas 数据框虽然共享许多相同的功能,但在分配数据的位置和方式上有所不同。
这一步是正确的:
test_df = test.toPandas()
Run Code Online (Sandbox Code Playgroud)
在使用 seaborn(甚至 matplotlib)绘图之前,您总是需要收集数据
| 归档时间: |
|
| 查看次数: |
7302 次 |
| 最近记录: |