-
Notifications
You must be signed in to change notification settings - Fork 14
/
export_data.py
36 lines (29 loc) · 935 Bytes
/
export_data.py
1
2
3
4
5
6
7
8
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
from shutil import copyfileobj
from nisystemlink.clients.dataframe import DataFrameClient
from nisystemlink.clients.dataframe.models import (
ColumnFilter,
ColumnOrderBy,
ExportFormat,
ExportTableDataRequest,
FilterOperation,
)
client = DataFrameClient()
# List a table
response = client.list_tables(take=1)
table = response.tables[0]
# Export table data with query options
request = ExportTableDataRequest(
columns=["col1"],
order_by=[ColumnOrderBy(column="col2", descending=True)],
filters=[
ColumnFilter(column="col1", operation=FilterOperation.NotEquals, value="0")
],
response_format=ExportFormat.CSV,
)
data = client.export_table_data(id=table.id, query=request)
# Write the export data to a file
with open(f"{table.name}.csv", "wb") as f:
copyfileobj(data, f)
# Alternatively, load the export data into a pandas dataframe
# import pandas as pd
# df = pd.read_csv(data)