TidyData: Constants

TidyData: Constants#

This section details how to do that.

Source Data#

The data source we’re using for these examples is shown below:

The full data source can be downloaded here.

from tidychef import acquire, preview
from tidychef.selection import CsvSelectable

# Argument is any csv file accessible via http or https
table: CsvSelectable = acquire.csv.http("https://raw.githubusercontent.com/mikeAdamss/tidychef/main/tests/fixtures/csv/bands-wide.csv")
preview(table)

Unnamed Table

ABCDEFGHIJK
1
2HousesCarsBoatsHousesCarsBoats
3BeatlesRolling Stones
4John159Keith2610
5Paul2610Mick3711
6George2711Charlie3812
7Ringo4812Ronnie5913
8

Declaring A Constant#

Delaring a constant value columns is a simple process and uses the syntax:

Column.constant(<column name>, <constant value>)

An example follows where we declare two columns of constants to go alongside a single directional column relationship.

from tidychef import acquire, preview, filters
from tidychef.direction import below
from tidychef.selection import CsvSelectable
from tidychef.output import TidyData, Column

# Argument is any csv file accessible via http or https
table: CsvSelectable = acquire.csv.http("https://raw.githubusercontent.com/mikeAdamss/tidychef/main/tests/fixtures/csv/bands-wide.csv")

observations = table.filter(filters.is_numeric).label_as("Value")
assets = table.excel_ref('2').is_not_blank().label_as("Assets Via Direction")

preview(observations, assets)

tidy_data = TidyData(
    observations,
    Column(assets.attach_directly(below)),
    Column.constant("Constant Foo", "Foo"),
    Column.constant("Constant Bar", "Bar")
)

print(tidy_data)
Value
Assets Via Direction

Unnamed Table

ABCDEFGHIJK
1
2HousesCarsBoatsHousesCarsBoats
3BeatlesRolling Stones
4John159Keith2610
5Paul2610Mick3711
6George2711Charlie3812
7Ringo4812Ronnie5913
8

ValueAssets Via DirectionConstant FooConstant Bar
1HousesFooBar
5CarsFooBar
9BoatsFooBar
2HousesFooBar
6CarsFooBar
10BoatsFooBar
2HousesFooBar
6CarsFooBar
10BoatsFooBar
3HousesFooBar
7CarsFooBar
11BoatsFooBar
2HousesFooBar
7CarsFooBar
11BoatsFooBar
3HousesFooBar
8CarsFooBar
12BoatsFooBar
4HousesFooBar
8CarsFooBar
12BoatsFooBar
5HousesFooBar
9CarsFooBar
13BoatsFooBar