Before you can analyze anything, you have to actually get your data into Python — and that first step trips up more beginners than the analysis itself. Python for data analysis has become the go-to approach for turning raw exports, databases, and APIs into real insight, thanks to its simplicity and a powerful ecosystem of libraries built specifically for this job.

If you’re a beginner web designer, this skill is more relevant than it might first appear. Client sites generate data constantly — form submissions, analytics exports, WooCommerce order histories, spreadsheet reports — and knowing how to pull that data into Python opens the door to building simple dashboards, automating reports, or just understanding a client’s traffic patterns more deeply.

This guide walks through the most common ways to access data in Python: reading CSV and Excel files, connecting to SQL databases, calling APIs, parsing JSON and XML, scraping websites, and working with cloud data sources — plus the best practices worth following from the start.

A handful of libraries cover almost every data access scenario you’ll run into:

  • Pandas — the core library for data manipulation and analysis, built around the DataFrame, a table-like structure for handling structured data.
  • NumPy — the foundational library for numerical computing, providing fast support for large, multi-dimensional arrays.
  • SQLAlchemy — an ORM (Object-Relational Mapping) toolkit and SQL abstraction layer that simplifies connecting to databases.
  • Requests — the standard library for calling web APIs and downloading data over HTTP.

Why This Matters for Web Designers

You don’t need a data science background to put this to use. A beginner web designer might use these same tools to pull a client’s contact-form submissions into a spreadsheet, analyze a WooCommerce sales export, or pull traffic numbers from an analytics API — all without leaving Python.

How to Access Data From Different Sources

1. CSV and Excel Files

CSV and Excel files are the most common way data gets handed to you — as a client export, a spreadsheet report, or a download from another tool. Pandas reads both with a single line:

import pandas as pd

# CSV file
df_csv = pd.read_csv("data/sales_data.csv")

# Excel file
df_excel = pd.read_excel("data/report.xlsx", sheet_name="Q1")

Reading .xlsx files requires the openpyxl engine, and older .xls files require xlrd:

pip install openpyxl xlrd

Pro tip: For large CSV files, use the chunksize parameter to process data in smaller batches and avoid running out of memory.

2. SQL Databases

Python connects to MySQL, PostgreSQL, SQLite, and other databases using sqlalchemy alongside a database-specific driver like pymysql:

from sqlalchemy import create_engine

# MySQL example
engine = create_engine("mysql+pymysql://user:password@localhost:3306/database_name")
df_sql = pd.read_sql("SELECT * FROM sales", engine)

Best practice: Use a context manager (a with block) to handle database connections, so they’re always closed properly even if an error occurs.

3. APIs (JSON Data)

The requests library is the standard way to pull data from web APIs, most of which return JSON:

import requests

response = requests.get("https://api.example.com/data")
data = response.json()
df_api = pd.DataFrame(data)

Security tip: Always store API keys in environment variables, never hardcoded directly in your script.

4. JSON and XML Files

Pandas reads JSON files directly, and Python’s built-in xml.etree.ElementTree module handles XML:

# JSON
df_json = pd.read_json("data/data.json")

# XML using ElementTree
import xml.etree.ElementTree as ET
tree = ET.parse("data/data.xml")
root = tree.getroot()

For deeply nested JSON structures, pd.json_normalize() flattens the data into a usable table.

5. Web Scraping

When data isn’t available through a file or an API, BeautifulSoup can extract it directly from a webpage’s HTML:

from bs4 import BeautifulSoup
import requests

url = "https://example.com/products"
page = requests.get(url)
soup = BeautifulSoup(page.content, "html.parser")
product_list = [item.text for item in soup.find_all("div", class_="product")]

For larger scraping projects, the Scrapy framework offers more structure and better performance.

6. Cloud and Big Data Sources

For larger-scale projects, Python also connects directly to:

  • AWS S3 using boto3
  • Google Cloud Storage using google-cloud-storage
  • Spark using PySpark

7. Parquet Files

CSV files are easy to open, but they are plain text: every number is stored as characters, nothing remembers whether a column was a date or an integer, and big files are slow to read. Parquet is a binary, column-oriented format designed for analysis. It is widely used in data engineering and in tools like Spark, and pandas reads it in one line.

pip install pyarrow
import pandas as pd

# Save a DataFrame as Parquet
df.to_parquet("data/sales.parquet", index=False)

# Read it back, loading only the columns you need
df = pd.read_parquet("data/sales.parquet", columns=["order_id", "total"])

Pandas needs a Parquet engine installed. pyarrow is the usual choice, and fastparquet is an alternative.

CSVParquet
FormatPlain textCompressed binary
File sizeLargerUsually much smaller
Read speedSlower on big filesFaster, especially when you need only some columns
Remembers data typesNoYes (dates, integers, and so on)
Opens in a text editor or ExcelYesNo
Best forSharing and quick exportsLarge datasets and repeated analysis

Because Parquet stores each column separately, columns=[...] reads only what you ask for instead of the whole file. A good habit is to convert a large CSV to Parquet once, then load the Parquet version for every later session.

8. Google Sheets

Clients often keep their data in a Google Sheet. The quickest way to read one is to ask Google for it as a CSV file. In the sheet, choose Share and set access to Anyone with the link can view, copy the sheet’s ID from the URL (the long string between /d/ and /edit), and build an export link:

import pandas as pd

sheet_id = "YOUR_SHEET_ID"
url = f"https://docs.google.com/spreadsheets/d/{sheet_id}/export?format=csv&gid=0"

df = pd.read_csv(url)

gid=0 is the first tab. Each tab has its own gid, visible in the URL when you select it.

Be careful with sensitive data. A “Anyone with the link” sheet can be opened by anyone who has the address. Do not use this method for customer lists, financial data, or anything private.

For private sheets, use the gspread library with a Google service account. You create the account in Google Cloud, share the sheet with the account’s email address, and authenticate with its key file. That setup takes more steps, but it keeps the data private and lets you write back to the sheet too. Keep the key file out of your code repository.

9. Going Further With SQLAlchemy

Section 2 showed the basics. Here are the habits that make database code safer and easier to reuse.

Connection strings follow the pattern dialect+driver://user:password@host:port/database:

DatabaseExampleExtra package
SQLite (a file, no server)sqlite:///shop.dbNone, it is built into Python
PostgreSQLpostgresql+psycopg2://user:pass@localhost:5432/shoppsycopg2-binary
MySQLmysql+pymysql://user:pass@localhost:3306/shoppymysql

SQLite is a good way to practice, since it needs no server. The example below creates a small database, writes a DataFrame into it, and then reads it back with a parameterized query:

import pandas as pd
from sqlalchemy import create_engine, text

engine = create_engine("sqlite:///shop.db")

orders = pd.DataFrame({
    "order_id": [1, 2, 3, 4],
    "customer": ["Ana", "Luis", "Marta", "Pedro"],
    "total": [35.50, 120.00, 58.25, 19.99],
})

# Write a DataFrame to a database table
orders.to_sql("orders", engine, if_exists="replace", index=False)

# Read with a parameter instead of building the SQL string yourself
query = text("SELECT * FROM orders WHERE total >= :min_total ORDER BY total DESC")
with engine.connect() as conn:
    big_orders = pd.read_sql(query, conn, params={"min_total": 50})

print(big_orders)

A few things worth noticing:

  • text() with :name placeholders keeps your values separate from the SQL, which protects you from SQL injection. Never paste user input into a query with an f-string. See SQL injection: how it works and how to prevent it.
  • The with block closes the connection for you, even if an error occurs.
  • to_sql() saves a DataFrame into a table. if_exists can be "fail", "replace", or "append". Use "replace" carefully, because it deletes the old table.
  • chunksize works with read_sql too. With chunksize=10000, you get an iterator that returns 10,000 rows at a time instead of loading everything at once.
  • Keep passwords out of your code. Read the connection string from an environment variable, for example create_engine(os.environ["DATABASE_URL"]). See Database Security and Privacy for more on protecting credentials.

To try this against a real server, follow the PostgreSQL beginner’s guide and change the connection string. For a deeper dive into SQLAlchemy itself, see the complete SQLAlchemy guide.

Best Practices for Accessing Data

  • Store credentials in environment variables or configuration files, never hardcoded in your script.
  • Load only the columns you actually need to reduce memory usage.
  • Cache intermediate results when working with large datasets, so you don’t reload data unnecessarily.
  • Validate data formats before loading, especially with Excel and XML files.
  • Check for missing values and inconsistencies as soon as data is loaded.
  • Write reusable functions for any data ingestion task you’ll repeat across projects.

Next Steps: From Data Access to Analysis

Once your data is loaded into a pandas DataFrame, the real work begins: filtering, aggregating, and merging it to find patterns. From there, visualization libraries like Matplotlib or Seaborn are the natural next step for turning your findings into charts a client can actually understand. To make sense of what you find, see statistics for data analysis.

Conclusion

Python for data analysis starts with one foundational skill: getting your data in. Whether it’s a CSV export, an Excel report, a SQL database, a JSON API, or data scraped straight from a webpage, Python’s ecosystem of libraries makes accessing nearly any data source genuinely approachable, even for a beginner.

Master the patterns in this guide — pandas for files and databases, requests for APIs, BeautifulSoup for scraping — and you’ll have a reusable toolkit for analyzing client data, automating reports, or exploring a personal project. Once the data is in, the far more interesting work of analysis is just one line of code away.