Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
I can loop through the output using
files = mssparkutils.fs.ls('Files/orders/')
for file in files:
print(file.name, file.isDir, file.isFile, file.path, file.size)
But how do I send the output to a dataframe instead?
Solved! Go to Solution.
Hi @PeteSpillane ,
You can do this with the following code
from notebookutils import mssparkutils
# Initialise variables
data = []
columns = ["File Name", "Is Dir", "Is File", "File Path", "File Size"]
files = mssparkutils.fs.ls('Files/orders/')
# Add rows to lists
for file in files:
data.append([file.name, file.isDir, file.isFile, file.path, file.size])
# Create a dataframe
dataframe = spark.createDataFrame(data, columns)
# Show data frame
dataframe.show()
Tested my side in Fabric notebook and all seemed to work okay.
Hope it helps,
Kris
Works perfectly. Thanks Kris!
Hi @PeteSpillane ,
You can do this with the following code
from notebookutils import mssparkutils
# Initialise variables
data = []
columns = ["File Name", "Is Dir", "Is File", "File Path", "File Size"]
files = mssparkutils.fs.ls('Files/orders/')
# Add rows to lists
for file in files:
data.append([file.name, file.isDir, file.isFile, file.path, file.size])
# Create a dataframe
dataframe = spark.createDataFrame(data, columns)
# Show data frame
dataframe.show()
Tested my side in Fabric notebook and all seemed to work okay.
Hope it helps,
Kris