Skip to main content

CSV Cheat Sheet

# Create a table
from deephaven.TableTools import emptyTable

source = emptyTable(100).update(
"X = 0.1 * i",
"SinX = X % 0.2 < 0.01 ? NULL_DOUBLE : sin(X)",
"CosX = cos(X)",
"TanX = tan(X)"
)

# Write to a local file
# `(null)` for null cells
from deephaven import write_csv

write_csv(source, "/data/TrigFunctions.csv")

# Write a subset of data
write_csv(source, "/data/Cosine.csv", ["X", "SinX"])

# Read from a local file
from deephaven import read_csv

result = read_csv("/data/TrigFunctions.csv")

# Read from a csv from URL
iris = read_csv("https://media.githubusercontent.com/media/deephaven/examples/main/Iris/csv/iris.csv")

# Read headerless, default column names
deniro_default = read_csv("https://media.githubusercontent.com/media/deephaven/examples/main/DeNiro/csv/deniro_headerless.csv", headless=True)

# Read headerless, provide names for header
import deephaven.Types as dht

header = {"Year": dht.int_, "Score": dht.int_, "Title": dht.string}
deniro_header = read_csv("https://media.githubusercontent.com/media/deephaven/examples/main/DeNiro/csv/deniro_headerless.csv", header=header, headless=True)

# Read files with other delimiters
deniro_TSV = read_csv("https://raw.githubusercontent.com/deephaven/examples/main/DeNiro/csv/deniro.tsv", delimiter="\t")
deniro_PSV = read_csv("https://raw.githubusercontent.com/deephaven/examples/main/DeNiro/csv/deniro.psv", delimiter="|")