Converting quarters into months
A company has a challenge in separating data into months. It has received the following data:
Quarter | Amount |
---|---|
Quarter 1 | 700 |
Quarter 2 | 650 |
The split across the months within each quarter is equal. Your goal is to separate this data into a list format containing the amounts per month for the first two quarters.
This is a part of the course
“Financial Forecasting in Python”
Exercise instructions
- Create a list for
quarters
containing the numerical units per quarter, and initialize a new empty listqrtlist
. The latter step has been done for you. - Create a for loop that converts the
qrt
in thequarters
list into months with the formularound(qrt/3, 2)
. Theround()
function with the second argument2
rounds the numbers down to a readable format. - Add the three equal values of
month
toqrtlist
. - Print the
qrtlist
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a list for quarters and initialize an empty list qrtlist
quarters = [____, 650]
qrtlist = []
# Create a for loop to split the quarters into months and add to qrtlist
for qrt in ____:
month = round(____ / 3, 2)
qrtlist = qrtlist + [____, ____, ____]
# Print the result
print("The values per month for the first two quarters are {}.".format(____))
This exercise is part of the course
Financial Forecasting in Python
Step into the role of CFO and learn how to advise a board of directors on key metrics while building a financial forecast.
We have gotten a basic understanding of income statements and balance sheets. However, consolidating data for forecasting is complex, so in this chapter, we will look at some basic tools to help solve some of the complexities specifically relating to finance - working with dates and different financial periods, and formatting our raw data into the correct format for financial forecasting.
Exercise 1: Financial periods and how to work with themExercise 2: Converting quarters into monthsExercise 3: Merging months into quartersExercise 4: The datetime libraryExercise 5: Working with the datetime libraryExercise 6: Converting date formats - simpleExercise 7: Converting date formats - explicitExercise 8: Tips and tricks when working with datasetsExercise 9: Working with datasets - month totalsExercise 10: Working with datasets - combining datasetsExercise 11: Working with datasets - exporting dataWhat is DataCamp?
Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.