Helpers
This module includes methods classified as helpers.
Anonymizer
A collection of methods to help handle sensitive information
pandasai.helpers.anonymizer
This module contains helper functions for anonymizing data and generating random data before sending it to the LLM (An External API). Only df.head() is sent to LLM API, hence the df.head() is processed to remove any personal or sensitive information.
anonymize_dataframe_head(data_frame, force_conversion=True)
Anonymize the head of a given DataFrame by replacing sensitive data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_frame |
pd.DataFrame
|
The DataFrame to anonymize the head data. |
required |
force_conversion |
bool
|
Convert it with instruction. Default is True. |
True
|
Source code in pandasai/helpers/anonymizer.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
copy_head(data_frame)
Copy the head of a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_frame |
pd.DataFrame
|
The pd.DataFrame to copy the head from. |
required |
Returns (pd.DataFrame): copied head of the DataFrame.
Source code in pandasai/helpers/anonymizer.py
122 123 124 125 126 127 128 129 130 131 132 | |
generate_random_credit_card()
Generate a random credit card number.
Returns (str): generated random credit card number.
Source code in pandasai/helpers/anonymizer.py
107 108 109 110 111 112 113 114 115 116 117 118 119 | |
generate_random_email()
Generates a random email address using predefined domains.
Returns (str): generated random email address.
Source code in pandasai/helpers/anonymizer.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | |
generate_random_phone_number(original_field)
Generate a random phone number with country code if originally present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_field |
str
|
original phone number field. |
required |
Returns (str): generated random phone number.
Source code in pandasai/helpers/anonymizer.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 | |
is_valid_credit_card(credit_card_number)
Check if the given credit card number is valid based on regex pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
credit_card_number |
str
|
credit card number to be checked. |
required |
Returns (str): True if the credit card number is valid, otherwise False.
Source code in pandasai/helpers/anonymizer.py
42 43 44 45 46 47 48 49 50 51 52 53 | |
is_valid_email(email)
Check if the given email is valid based on regex pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email |
str
|
email address to be checked. |
required |
Returns (bool): True if the email is valid, otherwise False.
Source code in pandasai/helpers/anonymizer.py
14 15 16 17 18 19 20 21 22 23 24 25 | |
is_valid_phone_number(phone_number)
Check if the given phone number is valid based on regex pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phone_number |
str
|
phone number to be checked. |
required |
Returns (bool): True if the phone number is valid, otherwise False.
Source code in pandasai/helpers/anonymizer.py
28 29 30 31 32 33 34 35 36 37 38 39 | |
Jupyter Notebook
Helper functions to handle Jupyter Notebook execution feature
pandasai.helpers.notebook
Helper Module to Handle Jupyter Notebook This module contains helper functions to interact with Jupyter Notebook Functionalities.
Notebook
Baseclass to implement Notebook helper functions
Source code in pandasai/helpers/notebook.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
create_new_cell(contents)
Creates a new code cell in the Jupyter notebook and populates it with the specified contents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contents |
str
|
The contents to be added to the new code cell. |
required |
ImportError
If the IPython module is not installed.
AttributeError
If the 'get_ipython()' call raises an AttributeError, which can happen if the code is not running inside a Jupyter notebook.
Source code in pandasai/helpers/notebook.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
in_notebook()
Checks whether the code is running inside a notebook environment.
Returns (bool): True if the code is running inside a Jupyter notebook, False otherwise.
Source code in pandasai/helpers/notebook.py
13 14 15 16 17 18 19 20 21 22 23 24 25 | |