首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >阿帕奇火种熊猫

阿帕奇火种熊猫
EN

Stack Overflow用户
提问于 2020-12-07 22:40:24
回答 2查看 65关注 0票数 0

我是阿帕奇星火公司的新手。我创建了模式和数据框架,它显示了结果,但是格式不太好,而且非常混乱。我几乎看不懂这句话。所以我想以熊猫的形式展示我的成绩。我附上了我的数据帧结果的屏幕截图。但是我不知道如何用熊猫来展示我的结果。

这是我的密码

代码语言:javascript
运行
复制
from pyspark.sql.types import StructType, StructField, IntegerType
from pyspark.sql.types import * 
from IPython.display import display 
import pandas as pd 
import gzip

schema = StructType([StructField("crimeid", StringType(), True), 
                     StructField("Month", StringType(), True), 
                     StructField("Reported_by", StringType(), True),
                     StructField("Falls_within", StringType(), True), 
                     StructField("Longitude", FloatType(), True), 
                     StructField("Latitue", FloatType(), True), 
                     StructField("Location", StringType(), True),
                     StructField("LSOA_code", StringType(), True),
                     StructField("LSOA_name", StringType(), True),
                     StructField("Crime_type", StringType(), True),
                     StructField("Outcome_type", StringType(), True),
                    ])

df = spark.read.csv("crimes.gz",header=False,schema=schema)
df.printSchema()

PATH = "crimes.gz"
csvfile = spark.read.format("csv")\
.option("header", "false")\
.schema(schema)\
.load(PATH)
df1 =csvfile.show()

它显示的结果如下

但是在想要这些数据熊猫形成

谢谢

EN

回答 2

Stack Overflow用户

发布于 2022-07-05 18:29:45

您可以尝试在每行垂直显示它们,或者如果您愿意,可以截断大名:

代码语言:javascript
运行
复制
df.show(2, vertical=True)
df.show(2, truncate=4, vertical=True)
票数 0
EN

Stack Overflow用户

发布于 2022-06-29 02:31:58

请尝试:

代码语言:javascript
运行
复制
from pyspark.sql.types import StructType, StructField, IntegerType
from pyspark.sql.types import * 
from IPython.display import display 
import pandas as pd 
import gzip

schema = StructType([StructField("crimeid", StringType(), True), 
                     StructField("Month", StringType(), True), 
                     StructField("Reported_by", StringType(), True),
                     StructField("Falls_within", StringType(), True), 
                     StructField("Longitude", FloatType(), True), 
                     StructField("Latitue", FloatType(), True), 
                     StructField("Location", StringType(), True),
                     StructField("LSOA_code", StringType(), True),
                     StructField("LSOA_name", StringType(), True),
                     StructField("Crime_type", StringType(), True),
                     StructField("Outcome_type", StringType(), True),
                    ])

df = spark.read.csv("crimes.gz",header=False,schema=schema)
df.printSchema()

pandasDF = df.toPandas() # transform PySpark dataframe in Pandas dataframe
print(pandasDF.head()) # print 5 first rows
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65190497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档