Pandas
PandasQueryEngine #
Bases: BaseQueryEngine
Pandas query engine.
Convert natural language to Pandas python code.
WARNING: This tool provides the Agent access to the eval
function.
Arbitrary code execution is possible on the machine running this tool.
This tool is not recommended to be used in a production setting, and would
require heavy sandboxing or virtual machines
Parameters:
Name | Type | Description | Default |
---|---|---|---|
df |
DataFrame
|
Pandas dataframe to use. |
required |
instruction_str |
Optional[str]
|
Instruction string to use. |
None
|
output_processor |
Optional[Callable[[str], str]]
|
Output processor. A callable that takes in the output string, pandas DataFrame, and any output kwargs and returns a string. eg.kwargs["max_colwidth"] = [int] is used to set the length of text that each column can display during str(df). Set it to a higher number if there is possibly long text in the dataframe. |
required |
pandas_prompt |
Optional[BasePromptTemplate]
|
Pandas prompt to use. |
None
|
head |
int
|
Number of rows to show in the table context. |
5
|
llm |
Optional[LLM]
|
Language model to use. |
None
|
Examples:
pip install llama-index-experimental
import pandas as pd
from llama_index.experimental.query_engine.pandas import PandasQueryEngine
df = pd.DataFrame(
{
"city": ["Toronto", "Tokyo", "Berlin"],
"population": [2930000, 13960000, 3645000]
}
)
query_engine = PandasQueryEngine(df=df, verbose=True)
response = query_engine.query("What is the population of Tokyo?")
Source code in llama-index-experimental/llama_index/experimental/query_engine/pandas/pandas_query_engine.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
|