
Monthly traded value
mediumMonthly traded value
Robinhood Pandas Interview Question
Robinhood's finance team reports the total value of shares traded each month, counting both buys and sells.
Using the trades DataFrame, find each month, written as text such as "2024-01", and the total value traded that month as traded_value, rounded to 2 decimal places. A trade's value is the number of shares times the price. Sort the rows by month, earliest first. Assign the answer to result.
Asked of
- Data Analyst
- Analytics Engineer
- Data Engineer
- Data Scientist
- ML Engineer
tradesDataFrame18 rows
| Column Name | Type |
|---|---|
| trade_id | int64 |
| user_id | int64 |
| symbol | str |
| side | str |
| shares | int64 |
| price | float64 |
| executed_at | str |
tradesExample Input
| trade_id | user_id | symbol | side | shares | price | executed_at |
|---|---|---|---|---|---|---|
| 61001 | 801 | AAPL | buy | 10 | 185.2 | 2024-01-04 09:35:12 |
| 61002 | 802 | TSLA | buy | 5 | 238.45 | 2024-01-09 10:02:44 |
| 61003 | 801 | NVDA | buy | 2 | 495.1 | 2024-01-22 13:15:05 |
| 61004 | 803 | AMZN | buy | 8 | 151.3 | 2024-01-30 15:42:18 |
| 61005 | 802 | TSLA | sell | 5 | 187.9 | 2024-02-06 09:48:31 |
| 61006 | 804 | AAPL | buy | 3 | 188.85 | 2024-02-13 11:21:09 |
| 61007 | 801 | AAPL | sell | 4 | 182.3 | 2024-02-20 14:05:57 |
| 61008 | 803 | NVDA | buy | 1 | 721.33 | 2024-02-27 10:30:00 |
| 61009 | 805 | AMZN | buy | 12 | 175.1 | 2024-03-01 09:31:40 |
| 61010 | 804 | TSLA | buy | 6 | 199.4 | 2024-03-08 12:44:23 |
Example Output
| month | traded_value |
|---|---|
| 2024-01 | 5244.85 |
| 2024-02 | 2956.58 |
| 2024-03 | 3297.6 |
Explanation
In January, four trades were worth 1,852.00, 1,192.25, 990.20 and 1,210.40, which adds up to 5,244.85. Buys and sells both count toward the value traded, and the months are listed from earliest to latest.
The example above is a small slice of the data. Your code runs against the full DataFrames.
Company
Robinhood
Difficulty
medium
Topic
dates
Language
Pandas
Your code
Loading Python in the background. You can start writing.