# Python

#### Get an overview of a dataframe

```python
import pandas as pd
import pandas_profiling as pp
# Load your DataFrame
# df = pd.read_csv('your_data.csv')
# Generate the report
report = pp.ProfileReport(df)
# To display in a Jupyter Notebook
report
```

#### Check if a file exists

```python
isExist = os.path.isfile(file_path)
```

#### Get the absolute path of a file

```python
abs_path = os.path.abspath(your_path)
```

#### Get all files in first level dir

```python
from os import listdir
from os.path import isfile, join
all_files_in_data_dir = [f for f in listdir(your_dir)
                         if isfile(join(your_dir, f))]
```

#### Get all files in a dir

```python
for path, subdirs, files in os.walk(root):
    for name in files:
        print os.path.join(path, name)
```

#### Get parent dir of current dir

```python
import os
d = os.path.dirname(os.getcwd())
```

#### Get all first-level sub dir of a folder

```python
all_sub_dir = [f.path for f in os.scandir(abs_input) if f.is_dir()]
```

#### Get the last part of folder

```python
os.path.basename(os.path.normpath('/folderA/folderB/folderC/folderD/'))
```

#### Get absolute path of a dir

```python
os.path.abspath("mydir/myfile.txt")
```

#### Sort by a column

```python
df.sort_values(by=['col1'])
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://juechen-yang.gitbook.io/juechen-s-codebook/python.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
