python-basic

⌘K
  1. Home
  2. Docs
  3. python-basic
  4. mkdocs

mkdocs

আমাদের অনেকের ডকুমেন্টেশন পড়ার অভ্যাস আছে কেমন হতো যদি আমাদের ই একটি ডকুমেন্টেশন থাকতো তাহলে খুব ভালো হতো পাইথন শেখার এখানেই সার্থকতা।

Activate Virtual Env

Step 1: Install MkDocs

First, ensure you have Python installed on your system. Then, you can install MkDocs using pip, the Python package manager:

pip install mkdocs
Bash

Step 2: Create a New MkDocs Project

Create a new directory for your documentation project and navigate into it:

mkdir mydocs
cd mydocs
Bash

Initialize a new MkDocs project:

mkdocs new .
Bash

Step 3: Choose a Theme

MkDocs comes with a default theme, but there are several third-party themes available. Let’s use the “Material for MkDocs” theme for this tutorial:

Install the theme using pip:

pip install mkdocs-material
Bash
site_name: My Documentation
theme:
  name: material
Bash

আমরা ইচ্ছা করলে readdos বেবহার করতে পারি কোনো কিছু ইনস্টল করা লাগবে না

site_name: MkLorum
site_url: https://example.com/
nav:
  - Home: index.md
  - About: about.md
theme: readthedocs
Bash

Step 4: Add Content

Navigate into the docs directory and start adding your documentation content. You can create Markdown (.md) files here. For example, create a file named index.md for your homepage and add some content:


# Environment Setup


First, ensure Python and necessary libraries are installed. For advanced data cleaning, libraries like Pandas, NumPy, and Matplotlib are crucial. If not already installed, you can install them using pip:

## Step 1: Package Installation
```bash
pip install numpy pandas matplotlib
```
    
## Step 2: Generate Demo Data
Let's create a synthetic dataset with typical issues such as missing values, outliers, and incorrect formats.

```python
import pandas as pd
import numpy as np

# Create a DataFrame
np.random.seed(0)
df = pd.DataFrame({
    'CustomerID': range(1, 101),
    'Age': np.random.normal(40, 10, 100).round(),
    'Income': np.random.normal(50000, 15000, 100).round(-2),
    'Gender': np.random.choice(['Male', 'Female', None], 100),
    'DateJoined': pd.to_datetime('2023-01-01') + pd.to_timedelta(np.random.randint(1, 365, 100), unit='d')
})

# Introduce missing values
df.loc[5:10, 'Age'] = np.nan
df.loc[15:20, 'Income'] = np.nan
df.loc[25:30, ['Gender', 'DateJoined']] = None

# Introduce outliers
df.loc[0, 'Age'] = -5
df.loc[1, 'Income'] = 200000

df.head()
```

## Step 3: Basic Data Cleaning
Now, we address common data issues including missing values, incorrect formats, and outliers.

Handling Missing Values

```python
# Fill missing 'Age' with median
df['Age'].fillna(df['Age'].median(), inplace=True)

# Fill missing 'Income' with the median
df['Income'].fillna(df['Income'].median(), inplace=True)

# Replace missing 'Gender' with mode
df['Gender'].fillna(df['Gender'].mode()[0], inplace=True)

# Drop rows where 'DateJoined' is missing
df.dropna(subset=['DateJoined'], inplace=True)
```
### Correcting Data Types and Formats
```python
# Ensure 'Age' is non-negative
df['Age'] = df['Age'].apply(lambda x: np.abs(x))

# Convert 'Income' to a proper numerical format if needed
df['Income'] = pd.to_numeric(df['Income'], errors='coerce').fillna(method='ffill')
```
Bash

Step 5: Customize Configuration

Open the mkdocs.yml file in your project directory. This is the configuration file for your MkDocs site. You can customize various settings here such as the site name, theme, and navigation. For example:

site_name: My Docs
nav:
  - Home: index.md
  - About: about.md
Bash

Step 6: Preview Your Site Locally

Run the following command to start a local development server and preview your site:

mkdocs serve
Bash

Step 7: Build Your Site

Once you’re satisfied with your documentation, you can build your site for deployment using the following command:

mkdocs build
Bash

This command will generate a static site in the site directory within your project folder.

Step 8: Deploy Your Site

You can deploy your MkDocs site to various platforms such as GitHub Pages, Netlify, or your own web server. For example, to deploy to GitHub Pages:

mkdocs gh-deploy
Bash

Articles

How can we help?