The world’s leading publication for data science, AI, and ML professionals.

Exploring Brent Oil Prices Data using Python

In this post we will perform some simple exploratory analysis on the Brent Oil Prices dataset. We start by importing the pandas library…

Photo by Pixabay on Pexels
Photo by Pixabay on Pexels

In this post, we will perform some simple exploratory analysis on the Brent Oil Prices dataset. We start by importing the pandas library and reading the data into a pandas data frame:

import pandas as pd
df = pd.read_csv("BrentOilPRices.csv")

We can also display the first five rows:

print(df.head())
First five rows of Brent oil price data
First five rows of Brent oil price data

Next, we can convert the ‘Date’ column into a datetime object and view the first five rows:

df['Date'] = pd.to_datetime(df['Date'])
print(df.head())
First five rows of Brent oil price data with datetime object timestamps
First five rows of Brent oil price data with datetime object timestamps

We can also view the last five rows of data:

print(df.head())
Last five rows of Brent oil price data
Last five rows of Brent oil price data

We can see from the data that the prices are from 1987–2019. We can also see that there are 8,216 rows of data. Next, we can plot the prices vs. time using the ‘seaborn’ data visualization package:

import seaborn as sns
sns.set()
plt.title('Brent Oil Prices')
sns.lineplot(df['Date'], df['Price'])
prices vs. time
prices vs. time

We can also look at the distribution of prices:

Histogram of Brent Oil Prices
Histogram of Brent Oil Prices

In the next post we will build a simple regression model to predict future Brent Oil prices. The code from this post is available on GitHub. Thanks for reading. Good luck and happy machine learning!


Related Articles