ylcnky
ylcnky

Reputation: 775

\List all DataFrames in Spark's current session/memory

I have 10s of DFs in PySpark assigned to different variable names such as: var1 = DF1, var2 = DF2, etc. Is there a built-in function in Spark/PySpark to list all DFs in memory/session? or any other way around?

Upvotes: 5

Views: 8039

Answers (1)

Alper t. Turker
Alper t. Turker

Reputation: 35249

You can adjust an answer from zero323:

def list_dataframes():
    from pyspark.sql import DataFrame
    return [k for (k, v) in globals().items() if isinstance(v, DataFrame)]

If object is registered then catalog will help:

spark = ...  # SparkSession

spark.catalog.listTables()

Upvotes: 9

Related Questions