Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
smpa01
Community Champion
Community Champion

Converting Fabric dataframe to spark dataframe

How can I convert a sempy.fabric.fabricdataframe to spark df?

The following does not work

 

dataset = (fabric
            .evaluate_dax(workspace= server,
            dataset=db,
            dax_string=query_string)
    ).to_pandas()


AttributeError: 'FabricDataFrame' object has no attribute 'to_pandas()'

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
frithjof_v
Community Champion
Community Champion

 

dataset = (fabric
            .evaluate_dax(workspace= server,
            dataset=db,
            dax_string=query_string)
    )

spark_df = spark.createDataFrame(dataset)

 

 

This works for me.

 

I think you can treat the Fabric dataframe as a Pandas dataframe, and convert it to a Spark dataframe the same way you would convert a Pandas dataframe to a Spark dataframe. 

 

https://learn.microsoft.com/en-us/fabric/data-science/semantic-link-overview#fabricdataframe-data-st...

 

"
The FabricDataFrame class:

  • Supports all pandas operations.
  • Subclasses the pandas DataFrame and adds metadata, such as semantic information and lineage.
  • (...)

"

View solution in original post

2 REPLIES 2
frithjof_v
Community Champion
Community Champion

 

dataset = (fabric
            .evaluate_dax(workspace= server,
            dataset=db,
            dax_string=query_string)
    )

spark_df = spark.createDataFrame(dataset)

 

 

This works for me.

 

I think you can treat the Fabric dataframe as a Pandas dataframe, and convert it to a Spark dataframe the same way you would convert a Pandas dataframe to a Spark dataframe. 

 

https://learn.microsoft.com/en-us/fabric/data-science/semantic-link-overview#fabricdataframe-data-st...

 

"
The FabricDataFrame class:

  • Supports all pandas operations.
  • Subclasses the pandas DataFrame and adds metadata, such as semantic information and lineage.
  • (...)

"

Liked the 1-liner; took a longer route which I can happily discard

# data_as_dict = dataset.to_dict()
# columns = dataset.columns

# flattened_rows = [Row(**{col: data_as_dict[col][i] for col in columns}) for i in range(len(data_as_dict[columns[0]]))]

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Fabric Update Carousel

Fabric Monthly Update - March 2026

Check out the March 2026 Fabric update to learn about new features.

Top Kudoed Authors