简体   繁体   中英

How do I present a single row of a PySpark dataframe vertically in Jupyter notebook output?

Have a need to display certain wide tables - single result vertically to be able to examine the record.

If I have code like the following:

def get_fiscal_df():
    q = "select * from fiscal_records where id = 'R20210106'"
    df = spark.sql(q)

df = get_fiscal_df()
df.show() # this would be replaced by new code/method

Is there something I could do (idiomatic) to show that would display that data like so:

Field Name Value
id R20210106
field2 value2
field3 value3
field4 value4
field5 value5

The only difference being I have inherited some tables that are 250 to 300 fields wide.

You can use df.show(vertical=True) to display the dataframe in vertical format, with each row/record having its own table.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM