0% found this document useful (0 votes)
126 views2 pages

Pandas Methods and Examples Guide

Uploaded by

hpatel63557
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
126 views2 pages

Pandas Methods and Examples Guide

Uploaded by

hpatel63557
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Pandas Methods with Examples

### 1. Data Creation


```python
import pandas as pd

# Create DataFrame
data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35]}
df = pd.DataFrame(data)

# Create Series
s = pd.Series([1, 2, 3], index=['a', 'b', 'c'])

# Read CSV (example assumes 'data.csv' exists)


df_csv = pd.read_csv('data.csv')

print(df)
print(s)
```

### 2. Viewing and Inspecting Data


```python
print(df.head()) # First 5 rows
print(df.info()) # Summary of DataFrame
print(df.describe()) # Statistics of numeric columns
print(df.shape) # (rows, columns)
print(df.columns) # Column names
```

### 3. Indexing and Selection


```python
# Access using loc and iloc
print(df.loc[0, 'Name']) # Label-based
print(df.iloc[0, 0]) # Position-based

# Subsetting
print(df[['Name', 'Age']]) # Select columns
print(df[df['Age'] > 28]) # Filter rows
```

You might also like