Python is a readable programming language used for many kinds of work, including data analysis. pandas is a Python library for exploring and transforming tabular data. This guide covers the basic Python concepts from the original article and adds a small pandas example so the title matches what the page teaches. You can practice in Google Colab or another Python environment.
What is Python?
Python is a high-level programming language designed to be readable. Its syntax makes it approachable for beginners, while its libraries support work in areas such as web development, automation, and data science.
Start in Google Colab
Google Colab provides an interactive notebook that runs in a browser. You can write and run Python cells without installing Python locally. Sign in to Colab, create a notebook, and enter a short expression such as 2 + 3 in a code cell.
Python fundamentals
These basics help you store values, display results, and organize a program.
Calculate with Python
Python supports common arithmetic operators, including +, -, *, /, and ** for exponentiation.
Create variables
A variable is a name that refers to a value. For example, age = 30 assigns the integer value 30 to the name age.
Print a result
Use print() to display a value or message:
name = "Mina"
print(name)
Combine strings and use f-strings
You can combine strings with +. An f-string is often clearer when you want to include a value inside a sentence:
name = "Mina"
message = f"Hello, {name}!"
print(message)
Common Python data types
Python includes several built-in types for representing values.
int: whole numbers, such as3or-2.float: numbers with a fractional part, such as2.5.str: text, such as"Hello".bool: one of two truth values,TrueorFalse.
Lists: keep values in order
A list stores an ordered collection of values. Create one with square brackets. Python list indexes start at zero:
topics = ["saving", "budgeting", "investing"]
print(topics[0]) # saving
Useful list methods
.append() adds an item, .remove() removes a matching item, and .sort() sorts the list in place. Choose the method that matches the result you need.
Dictionaries: connect keys and values
A dictionary stores key-value pairs. Use braces to create one, then look up or update a value by key:
person = {"name": "Mina", "city": "Bangkok"}
print(person["name"])
person["city"] = "Chiang Mai"
print("name" in person)
The in operator checks whether a key exists in a dictionary.
Functions: reuse a block of code
A function groups instructions under a name. Define a function with def, then call it by writing its name followed by parentheses:
def greet(name):
return f"Hello, {name}!"
print(greet("Mina"))
What is pandas?
pandas is a library for working with tabular data such as spreadsheets and database tables. Its main table structure is called a DataFrame. A DataFrame has labeled rows and columns and can be used to inspect, clean, and transform data.
Read and inspect a CSV file
Install pandas in an environment where it is not already available, then import it and read a CSV file:
import pandas as pd
data = pd.read_csv("sales.csv")
print(data.head())
print(data.info())
read_csv() loads comma-separated data into a DataFrame. head() shows the first rows so you can check what was loaded, and info() summarizes columns and data types. Check the file path, column names, missing values, and types before relying on the results.
Select rows and columns
Use .loc when selecting by labels and .iloc when selecting by integer position. For example, data.loc[0, "sales"] selects a value by row and column labels. See the official pandas documentation for more examples and details.
Keep learning with official documentation
- The official Python tutorial covers the language and its core data structures.
- The pandas getting-started guide introduces DataFrames and reading tabular data.
- Google Colab’s welcome notebook explains the interactive notebook environment.
Summary
Python fundamentals such as variables, data types, lists, dictionaries, and functions provide a base for writing programs. pandas adds tools for working with tables, and Google Colab offers one way to practice in a browser. Start with a small dataset, inspect the results, and consult the official documentation as you learn.
💬 Speak with a financial professional for a free consultation. Add us on LINE.
Or scan the QR code to add us.
