Post

Replies

Boosts

Views

Activity

Dataframe columns are ordered alphabetically when you print the dataframe
`import Cocoa import TabularData let greeting = "Decimal Type Evaluation" let JSON = """ [{     "product": "Apple",     "type": "Fruit",     "weight": 7.5,     "unit_price": 0.34 }, {     "product": "Pear",     "type": "Fruit",     "weight": 0.5,     "unit_price": 0.25 }] """ struct Product: Decodable {     let product: String     let type: String     let weight: Double     let unit_price: Double } let jsonData = JSON.data(using: .utf8)! let products: [Product] = try! JSONDecoder().decode([Product].self, from: jsonData) var dataframe = try! DataFrame(jsonData: jsonData) print (dataframe)` This results in the output below showing the columns are now ordered alphabetically and not in the order they appear in the array struct definition. ┏━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓ ┃   ┃ product  ┃ type     ┃ unit_price ┃ weight   ┃ ┃   ┃ <String> ┃ <String> ┃ <Double>   ┃ <Double> ┃ ┡━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩ │ 0 │ Apple    │ Fruit    │       0.34 │      7.5 │ │ 1 │ Pear     │ Fruit    │       0.25 │      0.5 │ └───┴──────────┴──────────┴────────────┴──────────┘ 2 rows, 4 columns
1
0
1.2k
Jul ’22
Regex expression in .split generates cannot convert type
Using Version 14.0 beta (14A5228q) on Monterey 12.4 I am trying to follow the 'Meet Swift regex' presentation dated 7 June but I have stumbled on the most basic of errors that I cannot get around. At 3:56 in the video, the following line of code is shown let transaction = "DEBIT 03/05/2022 Doug's Dugout Dogs $33.27" let fragments = transaction.split(separator: /\s{2,}|\t/) // ["DEBIT", "03/05/2022", "Doug's Dugout Dogs", "$33.27"]`` The '/' of the separator string generates the error: error: cannot convert value of type 'Regex' to expected argument type 'String.Element' (aka 'Character') I am embarrassed but also stuck on the simple issue and I cannot figure out what I am missing. TIA Chris
2
0
2.9k
Jun ’22
Dataframe columns are ordered alphabetically when you print the dataframe
`import Cocoa import TabularData let greeting = "Decimal Type Evaluation" let JSON = """ [{     "product": "Apple",     "type": "Fruit",     "weight": 7.5,     "unit_price": 0.34 }, {     "product": "Pear",     "type": "Fruit",     "weight": 0.5,     "unit_price": 0.25 }] """ struct Product: Decodable {     let product: String     let type: String     let weight: Double     let unit_price: Double } let jsonData = JSON.data(using: .utf8)! let products: [Product] = try! JSONDecoder().decode([Product].self, from: jsonData) var dataframe = try! DataFrame(jsonData: jsonData) print (dataframe)` This results in the output below showing the columns are now ordered alphabetically and not in the order they appear in the array struct definition. ┏━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━┓ ┃   ┃ product  ┃ type     ┃ unit_price ┃ weight   ┃ ┃   ┃ <String> ┃ <String> ┃ <Double>   ┃ <Double> ┃ ┡━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━┩ │ 0 │ Apple    │ Fruit    │       0.34 │      7.5 │ │ 1 │ Pear     │ Fruit    │       0.25 │      0.5 │ └───┴──────────┴──────────┴────────────┴──────────┘ 2 rows, 4 columns
Replies
1
Boosts
0
Views
1.2k
Activity
Jul ’22
Regex expression in .split generates cannot convert type
Using Version 14.0 beta (14A5228q) on Monterey 12.4 I am trying to follow the 'Meet Swift regex' presentation dated 7 June but I have stumbled on the most basic of errors that I cannot get around. At 3:56 in the video, the following line of code is shown let transaction = "DEBIT 03/05/2022 Doug's Dugout Dogs $33.27" let fragments = transaction.split(separator: /\s{2,}|\t/) // ["DEBIT", "03/05/2022", "Doug's Dugout Dogs", "$33.27"]`` The '/' of the separator string generates the error: error: cannot convert value of type 'Regex' to expected argument type 'String.Element' (aka 'Character') I am embarrassed but also stuck on the simple issue and I cannot figure out what I am missing. TIA Chris
Replies
2
Boosts
0
Views
2.9k
Activity
Jun ’22