Calculating Ideal Gas Law Parameters
Beginner Mode

Start your terminal to use beginner mode.

Objective

You are given two DataFrames, df_temperature and df_pressure, related to some thermodynamics experiments.

Task

Write a PySpark function that combines these DataFrames and creates the Result column using the formula for the Ideal Gas Law: Pressure * Temperature = Result. For each ExperimentID, multiply the Pressure and Temperature to calculate Result.

If there's an ExperimentID present in one DataFrame but not in the other, ignore that ExperimentID. Your solution should only contain ExperimentIDs that exist in both DataFrames.

Save your resulting DataFrame as result_df. Order the final output in ascending order by ExperimentID.

File Path

  • Temperature Dataset: /home/interview/temperature.csv
  • Pressure Dataset: /home/interview/pressure.csv
  • Starter script: /home/interview/thermodynamics.py

Schema

temperature.csv

Column Name Data Type
ExperimentID integer
Temperature double

pressure.csv

Column Name Data Type
ExperimentID integer
Pressure double

Expected Output Schema

Column Name Data Type
ExperimentID integer
Result double

Example

Given this sample input:

df_temperature

ExperimentID Temperature
1 273.15
2 293.15
3 313.15

df_pressure

ExperimentID Pressure
1 1.0
3 2.0
4 1.5

The expected output would be:

ExperimentID Result
1 273.15
3 626.3

Terminal requires a larger screen

Open this page on a desktop or tablet (≥ 768px) to launch the terminal and practice hands-on.

Linux Terminal Environment

Write and execute your solution in the terminal below.

Sign In

Track

Question Difficulty Company Access
Need more practice in this area? Explore more questions →