code: get_ipython().run_line_magic('pip', 'install llama-index-llms-openai')
  get_ipython().run_line_magic('pip', 'install llama-hub-llama-packs-tables-chain-of-table-base')
  
  
  get_ipython().system('wget "https://github.com/ppasupat/WikiTableQuestions/releases/download/v1.0.2/WikiTableQuestions-1.0.2-compact.zip" -O data.zip')
  get_ipython().system('unzip data.zip')
  
  
  
  import pandas as pd
  
  df = pd.read_csv("./WikiTableQuestions/csv/200-csv/3.csv")
  df
  
  
  
  from llama_index.packs.tables.chain_of_table.base import (
      ChainOfTableQueryEngine,
      serialize_table,
  )
  
  from llama_index.core.llama_pack import download_llama_pack
  
  download_llama_pack(
      "ChainOfTablePack",
      "./chain_of_table_pack",
      skip_load=True,
  )
  
  
  from llama_index.llms.openai import OpenAI
  
  llm = OpenAI(model="gpt-4-1106-preview")
  
  
  
  import phoenix as px
  import llama_index.core
  
  px.launch_app()
  llama_index.core.set_global_handler("arize_phoenix")
  
  
  
  
  import pandas as pd
  
  df = pd.read_csv("~/Downloads/WikiTableQuestions/csv/200-csv/11.csv")
  
  
  df
  
  
  query_engine = ChainOfTableQueryEngine(df, llm=llm, verbose=True)
  
  
  response = query_engine.query("Who won best Director in the 1972 Academy Awards?")
  
  
  str(response.response)
  
  
  
  import pandas as pd
  
  df = pd.read_csv("./WikiTableQuestions/csv/200-csv/42.csv")
  
  
  df
  
  
  query_engine = ChainOfTableQueryEngine(df, llm=llm, verbose=True)
  
  
  response = query_engine.query("What was the precipitation in inches during June?")
  
  
  str(response)
  
  
  
  from llama_index.core import PromptTemplate
  from llama_index.core.query_pipeline import QueryPipeline
  
  prompt_str = """\
  Here's a serialized table.
  
  {serialized_table}
  
  Given this table please answer the question: {question}
  Answer: """
  prompt = PromptTemplate(prompt_str)
  prompt_c = prompt.as_query_component(partial={"serialized_table": serialize_table(df)})
  
  
  
  qp = QueryPipeline(chain=[prompt_c, llm])
  response = qp.run("What was the precipitation in inches during June?")
  print(str(response))
  
  
  
  import pandas as pd
  
  df = pd.read_csv("./WikiTableQuestions/csv/203-csv/114.csv")
  df
  
  
  query_engine = ChainOfTableQueryEngine(df, llm=llm, verbose=True)
  response = query_engine.query("Which televised ABC game had the greatest attendance?")
  
  
  print(str(response))
  
  
  
  from llama_index.core import PromptTemplate
  from llama_index.core.query_pipeline import QueryPipeline
  
  prompt_str = """\
  Here's a serialized table.
  
  {serialized_table}
  
  Given this table please answer the question: {question}
  Answer: """
  prompt = PromptTemplate(prompt_str)
  prompt_c = prompt.as_query_component(partial={"serialized_table": serialize_table(df)})
  qp = QueryPipeline(chain=[prompt_c, llm])
  response = qp.run("Which televised ABC game had the greatest attendance?")
  print(str(response))
apis: llama_index.packs.tables.chain_of_table.base.ChainOfTableQueryEngine llama_index.core.PromptTemplate llama_index.packs.tables.chain_of_table.base.serialize_table llama_index.core.query_pipeline.QueryPipeline llama_index.core.llama_pack.download_llama_pack llama_index.llms.openai.OpenAI
extract_api: [((389, 442), 'pandas.read_csv', 'pd.read_csv', (['"""./WikiTableQuestions/csv/200-csv/3.csv"""'], {}), "('./WikiTableQuestions/csv/200-csv/3.csv')\n", (400, 442), True, 'import pandas as pd\n'), ((622, 707), 'llama_index.core.llama_pack.download_llama_pack', 'download_llama_pack', (['"""ChainOfTablePack"""', '"""./chain_of_table_pack"""'], {'skip_load': '(True)'}), "('ChainOfTablePack', './chain_of_table_pack', skip_load=True\n    )\n", (641, 707), False, 'from llama_index.core.llama_pack import download_llama_pack\n'), ((770, 804), 'llama_index.llms.openai.OpenAI', 'OpenAI', ([], {'model': '"""gpt-4-1106-preview"""'}), "(model='gpt-4-1106-preview')\n", (776, 804), False, 'from llama_index.llms.openai import OpenAI\n'), ((854, 869), 'phoenix.launch_app', 'px.launch_app', ([], {}), '()\n', (867, 869), True, 'import phoenix as px\n'), ((953, 1017), 'pandas.read_csv', 'pd.read_csv', (['"""~/Downloads/WikiTableQuestions/csv/200-csv/11.csv"""'], {}), "('~/Downloads/WikiTableQuestions/csv/200-csv/11.csv')\n", (964, 1017), True, 'import pandas as pd\n'), ((1040, 1090), 'llama_index.packs.tables.chain_of_table.base.ChainOfTableQueryEngine', 'ChainOfTableQueryEngine', (['df'], {'llm': 'llm', 'verbose': '(True)'}), '(df, llm=llm, verbose=True)\n', (1063, 1090), False, 'from llama_index.packs.tables.chain_of_table.base import ChainOfTableQueryEngine, serialize_table\n'), ((1230, 1284), 'pandas.read_csv', 'pd.read_csv', (['"""./WikiTableQuestions/csv/200-csv/42.csv"""'], {}), "('./WikiTableQuestions/csv/200-csv/42.csv')\n", (1241, 1284), True, 'import pandas as pd\n'), ((1307, 1357), 'llama_index.packs.tables.chain_of_table.base.ChainOfTableQueryEngine', 'ChainOfTableQueryEngine', (['df'], {'llm': 'llm', 'verbose': '(True)'}), '(df, llm=llm, verbose=True)\n', (1330, 1357), False, 'from llama_index.packs.tables.chain_of_table.base import ChainOfTableQueryEngine, serialize_table\n'), ((1708, 1734), 'llama_index.core.PromptTemplate', 'PromptTemplate', (['prompt_str'], {}), '(prompt_str)\n', (1722, 1734), False, 'from llama_index.core import PromptTemplate\n'), ((1831, 1867), 'llama_index.core.query_pipeline.QueryPipeline', 'QueryPipeline', ([], {'chain': '[prompt_c, llm]'}), '(chain=[prompt_c, llm])\n', (1844, 1867), False, 'from llama_index.core.query_pipeline import QueryPipeline\n'), ((1989, 2044), 'pandas.read_csv', 'pd.read_csv', (['"""./WikiTableQuestions/csv/203-csv/114.csv"""'], {}), "('./WikiTableQuestions/csv/203-csv/114.csv')\n", (2000, 2044), True, 'import pandas as pd\n'), ((2065, 2115), 'llama_index.packs.tables.chain_of_table.base.ChainOfTableQueryEngine', 'ChainOfTableQueryEngine', (['df'], {'llm': 'llm', 'verbose': '(True)'}), '(df, llm=llm, verbose=True)\n', (2088, 2115), False, 'from llama_index.packs.tables.chain_of_table.base import ChainOfTableQueryEngine, serialize_table\n'), ((2475, 2501), 'llama_index.core.PromptTemplate', 'PromptTemplate', (['prompt_str'], {}), '(prompt_str)\n', (2489, 2501), False, 'from llama_index.core import PromptTemplate\n'), ((2595, 2631), 'llama_index.core.query_pipeline.QueryPipeline', 'QueryPipeline', ([], {'chain': '[prompt_c, llm]'}), '(chain=[prompt_c, llm])\n', (2608, 2631), False, 'from llama_index.core.query_pipeline import QueryPipeline\n'), ((1801, 1820), 'llama_index.packs.tables.chain_of_table.base.serialize_table', 'serialize_table', (['df'], {}), '(df)\n', (1816, 1820), False, 'from llama_index.packs.tables.chain_of_table.base import ChainOfTableQueryEngine, serialize_table\n'), ((2568, 2587), 'llama_index.packs.tables.chain_of_table.base.serialize_table', 'serialize_table', (['df'], {}), '(df)\n', (2583, 2587), False, 'from llama_index.packs.tables.chain_of_table.base import ChainOfTableQueryEngine, serialize_table\n')]