Exploring Data using pandas

When you first load your data, it's important to perform initial checks to understand its structure, content, and the type of data it contains.

Viewing Data

Here's how you can take a peek at your DataFrame:

# Display the first five rows of the stocks DataFrame
print(stocks_df.head())

# Display the last five rows of the sDataFrame
print(stocks_df.tail())

financials_df.head() displays the first few rows and can immediately flag missing data or anomalies.

financials_df.tail() shows you the end of the dataset, often revealing how recent the data is and whether it's been truncated.

Data Structure

An understanding of your DataFrame's structure is essential before diving into deeper analysis.

We can use stocks_df.info() to get a summary of the DataFrame, including the number of non-null entries and data types of each column. This can highlight if certain columns contain missing values that need to be addressed or if data types need conversion.

# Print a concise summary of the DataFrame
print(stocks_df.info())

Descriptive Statistics

Descriptive statistics provide a high-level summary of the attributes of your dataset

  • stocks_df.describe() gives a statistical summary for numerical columns, useful for a quick assessment of distribution and variability.
  • Custom aggregations like stocks_df [' GOOGL '].mean() help in understanding specific aspects like the average.
# Get a statistical summary
print(stocks_df.describe())

# Find the average price for Google
print(stocks_df['GOOGL'].mean())

Aggregation

For more specific summary statistics, you can use aggregation methods like mean(), median(), min(), max(), and sum():

# Calculate the average opening price
print(stocks_df['MSFT'].mean())

# Find the maximum closing price
print(stocks_df['MSFT'].max())

The result The result will be 61.96290836653386 and 72.52.

Related Downloads

Finance Train Premium
Accelerate your finance career with cutting-edge data skills.
Join Finance Train Premium for unlimited access to a growing library of ebooks, projects and code examples covering financial modeling, data analysis, data science, machine learning, algorithmic trading strategies, and more applied to real-world finance scenarios.
I WANT TO JOIN
JOIN 30,000 DATA PROFESSIONALS

Free Guides - Getting Started with R and Python

Enter your name and email address below and we will email you the guides for R programming and Python.

Saylient AI Logo

Accelerate your finance career with cutting-edge data skills.

Join Finance Train Premium for unlimited access to a growing library of ebooks, projects and code examples covering financial modeling, data analysis, data science, machine learning, algorithmic trading strategies, and more applied to real-world finance scenarios.