Skip to content

Instantly share code, notes, and snippets.

import csv
from tableauhyperapi import HyperProcess, Telemetry, Connection, CreateMode, NOT_NULLABLE, NULLABLE, SqlType, \
TableDefinition, Inserter, escape_name, escape_string_literal, HyperException, TableName
with HyperProcess(telemetry=Telemetry.DO_NOT_SEND_USAGE_DATA_TO_TABLEAU) as hyper:
print("starting up Hyper Process")
with Connection(hyper.endpoint, 'hyper/pokemon_hyper_api.hyper', CreateMode.CREATE_AND_REPLACE) as connection:
print("creating or replacing pokemon_hyper_api.hyper")
poke_table = TableDefinition(TableName('public','pokemon'), [
df1 = pd.read_csv("data/starter_pokemon_grass.csv")
df2 = pd.read_csv("data/starter_pokemon_fire.csv")
df3 = pd.read_csv("data/starter_pokemon_water.csv")
dict_df = {"grass": df1, "fire": df2, "water": df3}
pantab.frames_to_hyper(dict_df, "hyper/all_pokemon_separate.hyper")
# append all DataFrames into one before writing to single table in Hyper
final_df = df1.append(df2).append(df3).reset_index(drop=True)
pantab.frames_to_hyper({"pokemon": final_df}, "hyper/all_pokemon_in_one.hyper")
# this produces the same result as above
pantab.frame_to_hyper(df1, "hyper/all_pokemon_append.hyper", table = "pokemon")
pantab.frame_to_hyper(df2, "hyper/all_pokemon_append.hyper", table = "pokemon", table_mode = "a")
pantab.frame_to_hyper(df3, "hyper/all_pokemon_append.hyper", table = "pokemon", table_mode = "a")
@c-l-nguyen
c-l-nguyen / employee_dept_icicle.csv
Created June 6, 2021 19:32
Data for icicle chart
ID Label Level Level ID Value
1 A HR 1 20
1 B IT 1 30
1 C Sales 1 15
1 D Finance 1 35
2 A1 HR 2 10
3 A2 HR 2 5
4 A3 HR 2 5
2 B1 IT 2 15
3 B2 IT 2 15