# Pandas: Import and Export

## Pandas CSV

Work with CSV files, read and write like a boss.

Example 1: Read a CSV file.

```python
df = pd.read_csv('file.csv')
```

Example 2: Write a DataFrame to CSV.

```python
df.to_csv('output.csv', index=False)
```

Handle CSVs like a data wizard.

---

## Pandas JSON

Handle JSON data with ease.

Example 1: Read JSON.

```python
df = pd.read_json('file.json')
```

Example 2: Write JSON.

```python
df.to_json('output.json', orient='records')
```

JSON is your gateway to modern data formats.

---

## Pandas Cleaning Data

Clean data faster than your roommate avoids doing dishes.

Example 1: Strip whitespace.

```python
df['Column'] = df['Column'].str.strip()
```

Example 2: Standardize case.

```python
df['Column'] = df['Column'].str.lower()
```

Clean data, clean mind.

---

## Pandas Missing Values

Handle missing values like a pro.

Example 1: Fill missing values.

```python
df = pd.DataFrame({'A': [1, None, 3]})
df.fillna(0, inplace=True)
```

Example 2: Drop rows with missing data.

```python
df.dropna(inplace=True)
```

Because no one likes a blank space (thanks, Taylor Swift).

---

## Pandas Handling Wrong Format

Fix your messy data formats.

Example 1: Convert strings to dates.

```python
df['Date'] = pd.to_datetime(df['Date'])
```

Example 2: Convert strings to numbers.

```python
df['Numeric'] = pd.to_numeric(df['Numeric'], errors='coerce')
```

Wrong format? Not anymore.

---

## Pandas Handling Wrong Data

Replace invalid values.

Example: Replace placeholders with `None`.

```python
df['Column'] = df['Column'].replace('?', None)
```

No more wrong data ruining your day.

---

## Pandas Get Dummies

Convert categories to indicator variables.

Example: Create dummy variables.

```python
dummies = pd.get_dummies(df['Category'])
print(dummies)
```

Perfect for machine learning models.

---

## Pandas Categorical

Optimize memory usage with categorical data types.

Example: Convert to categorical.

```python
df['Category'] = df['Category'].astype('category')
```

Save memory, save the planet.

---

## Pandas Datetime

Work with datetime like a pro.

Example 1: Extract the year.

```python
df['Year'] = pd.to_datetime(df['Date']).dt.year
```

Example 2: Extract the month.

```python
df['Month'] = pd.to_datetime(df['Date']).dt.month
```

DateTime makes time manipulation a breeze.

---

## Pandas Aggregate Functions

Summarize data efficiently.

Example: Group by and aggregate.

```python
grouped = df.groupby('Category').agg({'Value': 'sum'})
print(grouped)
```

Aggregations are the secret sauce to insights.

---

## Pandas Group By

Group data for analysis.

Example: Group and calculate mean.

```python
print(df.groupby('Category').mean())
```

Group by like a data Jedi.

---

## Pandas Filtering

Filter rows based on conditions.

Example: Filter rows.

```python
df[df['Value'] > 10]
```

Keep what you love, ditch the rest.

---

## Pandas Sort

Sort data like a pro.

Example 1: Sort rows by a column.

```python
df.sort_values(by='Value', ascending=False, inplace=True)
```

Example 2: Sort by index.

```python
df.sort_index(inplace=True)
```

Sorting is as easy as pie.

---

## Pandas Correlation

Check correlations between numerical columns.

Example: Compute correlation.

```python
print(df.corr())
```

Correlation = your shortcut to patterns.

---

## Pandas Plot

Visualize data without leaving Pandas.

Example: Line plot.

```python
df.plot(kind='line')
```

Example: Bar plot.

```python
df.plot(kind='bar')
```

Pandas plotting is your gateway to quick insights.

---

## Pandas Histogram

Understand distributions with histograms.

Example 1: Simple histogram.

```python
df['Value'].hist()
```

Example 2: Multiple histograms.

```python
df[['A', 'B']].hist()
```

Histograms: because data speaks louder than words.
