Get startedGet started for free

Taking the difference

In this exercise, you will to prepare a time series of the population of a city for modeling. If you could predict the growth rate of a city then it would be possible to plan and build the infrastructure that the city will need later, thus future-proofing public spending. In this case the time series is fictitious but its perfect to practice on.

You will test for stationarity by eye and use the Augmented Dicky-Fuller test, and take the difference to make the dataset stationary.

The DataFrame of the time series has been loaded in for you as city and the adfuller() function has been imported.

This exercise is part of the course

ARIMA Models in Python

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Run the ADF test on the time series
result = ____(____)

# Plot the time series
fig, ax = plt.subplots()
city.plot(ax=ax)
plt.show()

# Print the test statistic and the p-value
print('ADF Statistic:', ____)
print('p-value:', ____)
Edit and Run Code