Pandas_Tutorial
Pandas_Tutorial
Introduction to Pandas
1. Introduction to Pandas
Pandas is built on top of NumPy and provides two primary data structures: Series and DataFrame.
Series
import pandas as pd
# Creating a Series
s = pd.Series([1, 3, 5, 7, 9])
print(s)
DataFrame
A DataFrame is a two-dimensional labeled data structure with columns of potentially different types.
# Creating a DataFrame
data = {
df = pd.DataFrame(data)
Introduction to Pandas
print(df)
Viewing Data
print(df.head())
print(df.tail())
print(df.info())
print(df.describe())
Selecting Data
# Select a column
print(df['Name'])
print(df[['Name', 'City']])
Introduction to Pandas
print(df.iloc[1:3])
3. Data Manipulation
- Dropping columns.
print(df)
# Dropping a column
df = df.drop(columns=['Country'])
print(df)
Filtering Data
print(filtered_df)
data = {
df = pd.DataFrame(data)
print(df.isnull())
print(df_filled)
df_dropped = df.dropna()
print(df_dropped)
data = {
df = pd.DataFrame(data)
grouped_df = df.groupby('Category').sum()
print(grouped_df)
- Concatenation.
Introduction to Pandas
# Concatenation
print(result)
# Merging
print(result)
Pivot Tables
data = {
df = pd.DataFrame(data)
print(pivot_table)
Applying Functions
print(df)
Conclusion
This is a brief overview of some of the basic and intermediate functionalities of pandas. As you work
more with pandas, you'll discover many more powerful features and methods that can help you
manipulate and analyze data efficiently. Practice is key, so try to work on different datasets and use