How to Collect Data for a Data Analysis Project: A Beginner’s Guide

Every data analysis project begins with a question—but you cannot answer that question without data. For beginners, finding the right data can feel confusing:

  • Where can I find a dataset?
  • Can I download data for free?
  • What is an API?
  • When should I use web scraping?
  • Am I allowed to collect data from any website?

In this guide, you will learn four practical ways to collect data:

  1. Built-in datasets from Python libraries
  2. Datasets from Kaggle
  3. Data collected through APIs
  4. Data collected through web scraping
Before Collecting Data, Define Your Goal

Do not select a dataset only because it looks interesting. Before collecting data, clearly define the problem you want to investigate.

Example Business Problem

A retail company wants to understand which products, regions and customer groups generate the most revenue.

Based on this problem, you may need the following information:

  • Order date
  • Product name
  • Product category
  • Customer information
  • Region
  • Quantity
  • Product price
  • Total sales amount
Remember: Defining the problem first prevents you from downloading a dataset that cannot answer your business questions.
Four Ways to Collect Data

Beginners can collect data using several methods. The method you choose depends on your project goal, technical skills and the availability of data.

Four ways to collect data using Scikit-learn, Kaggle, APIs and web scraping

Regardless of the source, the collected data can usually be converted into a Pandas DataFrame for inspection, cleaning, analysis and visualization.

Method 1
Use Built-In Scikit-Learn Datasets

Scikit-learn provides small, ready-to-use datasets for learning data analysis and machine learning.

These datasets are useful when you want to:

  • Practise Python and Pandas
  • Learn data exploration
  • Test a machine-learning model
  • Focus on coding instead of searching for data
Common Scikit-Learn Datasets
Dataset Possible Use
Iris Flower classification
Wine Wine classification
Breast Cancer Binary classification
Diabetes Regression analysis
California Housing House-value prediction
Digits Image classification
Example: Load the Iris Dataset
from sklearn.datasets import load_iris
import pandas as pd

iris = load_iris(as_frame=True)

df = iris.frame

print(df.head())

The as_frame=True option returns the dataset in a Pandas-friendly format.

You can now inspect the dataset:

print(df.shape)
print(df.columns)
print(df.info())
print(df.describe())
Load a Dataset from OpenML

Scikit-learn can also retrieve datasets from OpenML.

from sklearn.datasets import fetch_openml

titanic = fetch_openml(
    name="titanic",
    version=1,
    as_frame=True
)

df = titanic.frame

print(df.head())
Limitation: Built-in datasets are excellent for learning, but many are too small or commonly used to create a distinctive portfolio project.
Official Scikit-Learn Resource

Explore the built-in, downloadable and generated datasets available through Scikit-learn.

Explore Scikit-Learn Datasets
Official OpenML Resource

Search for additional public datasets available through OpenML.

Explore OpenML Datasets
Method 2
Download a Dataset from Kaggle

Kaggle provides thousands of public datasets that can be used for learning, practice and portfolio projects.

You can find datasets related to:

  • Retail and e-commerce
  • Finance
  • Healthcare
  • Marketing
  • Human resources
  • Sports
  • Transportation
  • Customer behaviour
  • Climate and environment
  • Social media
How to Find a Dataset on Kaggle
  1. Visit the Kaggle website and create or sign in to your account.
  2. Open the Datasets section.
  3. Search using a business topic or industry.
  4. Open the dataset page.
  5. Read the dataset description.
  6. Review the available files and columns.
  7. Check the licence and usage conditions.
  8. Download and extract the dataset files.
Avoid a General Search

Pandas dataset

Load a Downloaded CSV File
import pandas as pd

df = pd.read_csv("customer_data.csv")

print(df.head())
Load an Excel File
df = pd.read_excel("customer_data.xlsx")
Load a JSON File
df = pd.read_json("customer_data.json")
What Should You Check Before Choosing a Dataset?
  • Does the dataset support a clear business problem?
  • What does each row represent?
  • What does each column represent?
  • Are there enough records for meaningful analysis?
  • Is a data dictionary available?
  • Are important fields missing?
  • Is the dataset legally available for reuse?
  • Can you produce original insights from it?
A good portfolio project does not depend only on dataset size. It depends on the quality of the business problem, analysis, insights and recommendations.
Official Kaggle Resource

Search for datasets by topic, industry, file type, size and usability.

Explore Kaggle Datasets
Official Kaggle Command-Line Tool

After learning manual downloads, you can use Kaggle’s official command-line tool to search for and download datasets.

View the Official Kaggle CLI
Method 3
Collect Data Using an API

An API allows one application to request data from another application.

An API may provide information such as:

  • Weather conditions
  • Currency exchange rates
  • Stock-market data
  • Public transportation information
  • Government records
  • Product information
  • Sports results
Python Request
API
JSON Response
Pandas DataFrame
Beginner API Example
import requests
import pandas as pd

url = "https://api.example.com/products"

response = requests.get(
    url,
    timeout=30
)

response.raise_for_status()

data = response.json()

df = pd.DataFrame(data)

print(df.head())

The raise_for_status() method checks whether the API request was successful before the response is processed.

Send Parameters with an API Request

Parameters allow you to control which information the API returns.

params = {
    "city": "Edmonton",
    "start_date": "2026-01-01"
}

response = requests.get(
    "https://api.example.com/weather",
    params=params,
    timeout=30
)
Use an API Key

Some APIs require users to register and receive an API key.

headers = {
    "Authorization": "Bearer YOUR_API_KEY"
}

response = requests.get(
    "https://api.example.com/data",
    headers=headers,
    timeout=30
)
Protect Your API Key

Never publish your API key in:

  • A public notebook
  • A GitHub repository
  • A screenshot
  • A portfolio article
Common API Challenges
  • Request limits
  • Authentication requirements
  • Multiple pages of results
  • Missing records
  • Nested JSON data
  • Paid usage plans
  • Data-usage restrictions
Always read the API documentation before requesting and using its data.
Official Python Requests Resource

Learn how to send API requests, use parameters, check responses and process JSON data.

Learn Python API Requests
Method 4
Collect Data Through Web Scraping

Web scraping means using code to extract information displayed on a webpage.

Web scraping may be useful when:

  • The website does not provide a downloadable dataset.
  • No suitable API is available.
  • The information appears in repeated HTML elements.
  • You have permission to collect and use the information.

Possible examples include:

  • Product names and prices
  • Public event listings
  • Public tables
  • Article titles
  • Permitted public job listings
Understand the Webpage Structure

A webpage is created using HTML elements. For example:

<div class="product">
    <h2 class="name">Laptop</h2>
    <span class="price">$899</span>
</div>

Python can locate these elements and collect the text stored inside them.

Basic Web-Scraping Example
import requests
from bs4 import BeautifulSoup
import pandas as pd

url = "https://example.com/products"

response = requests.get(
    url,
    timeout=30
)

response.raise_for_status()

soup = BeautifulSoup(
    response.text,
    "html.parser"
)

products = []

for item in soup.find_all(
    "div",
    class_="product"
):
    name = item.find(
        "h2",
        class_="name"
    )

    price = item.find(
        "span",
        class_="price"
    )

    products.append({
        "product_name": name.get_text(strip=True),
        "price": price.get_text(strip=True)
    })

df = pd.DataFrame(products)

print(df.head())
Save the Collected Data
df.to_csv(
    "collected_products.csv",
    index=False
)
Responsible Web Scraping

Publicly visible information is not automatically available for unrestricted collection or reuse.

  • Review the website’s terms of service.
  • Check its robots.txt instructions.
  • Prefer an official API when one is available.
  • Do not collect private, personal or sensitive information.
  • Do not bypass logins or security controls.
  • Do not send a large number of rapid requests.
  • Respect copyright, privacy and licensing requirements.
  • Stop if automated data collection is prohibited.

You can add a short delay between requests:

import time

time.sleep(2)
Web scraping should be used carefully and responsibly—not simply because it is technically possible.
Official Beautiful Soup Resource

Learn how Beautiful Soup finds, navigates and extracts information from HTML pages.

Learn Beautiful Soup
Other Common Data Sources

In real organizations, data analysts may also collect data from:

CSV, Excel, JSON and text files
SQL databases
Company CRM systems
Sales and marketing platforms
Google Forms and surveys
Government open-data portals
Public research repositories
Cloud storage systems
Internal business applications
Beginners should first learn to work with downloadable files before moving to APIs, databases and web scraping.
Which Data Collection Method Should You Choose?
Method Best Used For Difficulty
Scikit-learn datasets Learning Python and machine learning Easy
Kaggle datasets Practice and portfolio projects Easy
Public APIs Current or regularly updated data Intermediate
Web scraping Permitted webpage data without an API Intermediate
Company databases Real business analysis Intermediate–Advanced
Surveys and forms Collecting original data Easy–Intermediate
Recommended Learning Order for Beginners
1
Load a built-in Scikit-learn dataset.
2
Download and analyze a CSV file from Kaggle.
3
Retrieve JSON data from a simple public API.
4
Convert the API response into a Pandas DataFrame.
5
Scrape one permitted static webpage.
6
Save the collected information as a CSV file.
7
Validate and document the collected data.
Always Validate Your Collected Data

Collecting data is not the end of the process. Before beginning your analysis, confirm that the data was collected correctly.

print(df.head())
print(df.shape)
print(df.columns)
print(df.dtypes)
print(df.isnull().sum())
print(df.duplicated().sum())
Ask These Validation Questions
  • Did I receive the expected number of records?
  • Are all required columns present?
  • Are the data types correct?
  • Are important values missing?
  • Does the dataset contain duplicate records?
  • Does each row represent what I expected?
  • When was the data collected or updated?
Never begin your analysis without confirming that the collected data is complete, relevant and understandable.
Final Takeaway

There is no single best way to collect data.

  • Use Scikit-learn for quick learning exercises.
  • Use Kaggle for accessible practice and portfolio datasets.
  • Use APIs for structured and regularly updated information.
  • Use web scraping only when it is appropriate, permitted and necessary.

Most importantly, begin with a clear question. The best dataset is not necessarily the largest or most popular—it is the dataset that helps you answer a meaningful problem.