tenFrame quick start
If you are familiar with pandas, you can get up and running with tenFrame in about 10 minutes.
To start using tenFrame, import py1010 and tenFrame as follows:
import py1010 import tenFrame as tf
Opening a 1010data table and creating a TenFrame
retailitem
based on a 1010data session and the table
pub.demo.retail.item
.session = py1010.Session("1010data URL", "USERNAME", "PASSWORD", py1010.POSSESS) retailitem = tf.TenFrame(session, "pub.demo.retail.item")
1010data
URL
is the gateway and version you use to access 1010data.
USERNAME
and PASSWORD
are the user name
and password you use to access 1010data.Viewing the TenFrame
If you print a TenFrame, you can view the first 10 entries of the table:
You can also use
the .head()
and .tail()
methods to view the top
and bottom rows of the TenFrame, respectively:
To download all your data, use
.to_df()
to convert the TenFrame to a pandas DataFrame (image
truncated):
Use .describe()
to get basic statistics for your
TenFrame (in this example just the sales
and cost
columns):
Selecting data
You can select a single column, which yields a TenSeries:
You can select rows of data using an expression:
You can also select a "slice" of rows:
Calculating new data and subsetting columns
Place the new column name in brackets and add an expression to create a calculated
column. You can also subset the desired columns, in this case,
sales
, cost
, and margin
:
Combining TenFrames
You can combine TenFrames in several ways.
Merge TenFrames on a column using a left join, in this case, using the
sku
column to merge a transaction TenFrame with a product
detail TenFrame:
Concatenate TenFrames together by either appending the rows (axis=0
)
or columns (axis=1
):
Grouping data
Use the groupby()
method to indicate the group(s) to aggregate. Then
you can use aggregation functions, such as .sum()
, to aggregate
data of one or more columns:
The .agg()
function allows you to do more complex aggregations on
multiple columns:
Creating a pivot table
Use the pivot_table()
method to create a pivot table. A pivot table
(or cross tabulation, in 1010data terms) allows you to calculate the values in a
column based on the values in two or more other columns and display the result as a
matrix. The following pivot table groups the total sales by customer key, and also
provides the sales breakdown for each department: