Can you explain what you wrote? Does the filter modify the original DataFrame?
💡 Model Answer
In Spark, DataFrames are immutable. The filter transformation does not modify the original DataFrame; instead, it returns a new DataFrame that contains only the rows that satisfy the predicate. The original DataFrame remains unchanged and can still be used elsewhere. This immutability is a core design principle of Spark’s RDD and DataFrame APIs, allowing transformations to be safely composed and cached without side effects. If you want to keep the filtered result, you must assign it to a new variable or overwrite the existing one, e.g., orders_filtered = orders.filter(col('status') == 'Completed'). The original orders DataFrame will still contain all rows.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500