Reputation: 775
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
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