Skip to content

Instantly share code, notes, and snippets.

@winslowdibona
Last active December 18, 2020 00:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save winslowdibona/70591003973a98f030c86a89947d3a28 to your computer and use it in GitHub Desktop.
Save winslowdibona/70591003973a98f030c86a89947d3a28 to your computer and use it in GitHub Desktop.
csv-etl example
rules:
-
target: OrderId
type: Calculation
input_type: Integer
output_type: Integer
source: Order Number
-
target: OrderDate
type: Calculation
input_type: Integer
output_type: Date
source:
- Day
- Month
- Year
operations:
- "datetime(s[2], s[1], s[0])"
-
target: ProductId
type: Calculation
input_type: String
output_type: String
source: Product Number
-
target: ProductName
type: Calculation
input_type: String
output_type: String
source: Product Name
operations:
- "s.title()"
-
target: Quantity
type: Calculation
input_type: Decimal
output_type: Decimal
source: Count
-
target: Unit
type: Static
input_type: String
output_type: String
source: kg
pip install csv-etl
# result as json
csv-etl ./config.yaml ./test_data.csv
# result as csv
csv-etl ./config.yaml ./test_data.csv --format=csv
# result as written to csv file
csv-etl ./config.yaml ./test_data.csv --format=csv --outfile=./result.csv
Order Number Year Month Day Product Number Product Name Count Extra Col1 Extra Col2 Empty Column
1000 2018 1 1 P-10001 Arugola 5,250.50 Lorem Ipsum
1001 2017 12 12 P-10002 Iceberg lettuce 500.00 Lorem Ipsum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment