flatten

AutoMapper and flattening nested arrays

妖精的绣舞 提交于 2019-12-17 18:29:50
问题 I'm trying to use AutoMapper to flatten multiple levels of arrays. Consider the following source classes: class X { public string A { get; set; } public Y[] B { get; set; } } class Y { public string C { get; set; } public Z[] D { get; set; } } class Z { public string E { get; set; } public string F { get; set; } } And the following destination: class Destination { public string A { get; set; } public string C { get; set; } public string E { get; set; } public string F { get; set; } } What I'd

flattening nested Json in pandas data frame

Deadly 提交于 2019-12-17 16:52:31
问题 I am trying to load the json file to pandas data frame. I found that there were some nested json. Below is the sample json: {'events': [{'id': 142896214, 'playerId': 37831, 'teamId': 3157, 'matchId': 2214569, 'matchPeriod': '1H', 'eventSec': 0.8935539999999946, 'eventId': 8, 'eventName': 'Pass', 'subEventId': 85, 'subEventName': 'Simple pass', 'positions': [{'x': 51, 'y': 49}, {'x': 40, 'y': 53}], 'tags': [{'id': 1801, 'tag': {'label': 'accurate'}}]} I used the following code to load json

flatten and flatMap in scala

末鹿安然 提交于 2019-12-14 03:35:58
问题 I'll like to check if I have understood flatten and flatMap functions correctly. 1) Am I correct that flatten works only when a collection constitutes of other collections. Eg flatten would work on following lists //list of lists val l1 = List(List(1,1,2,-1,3,1,-4,5), List("a","b")) //list of a set, list and map val l2 = List(Set(1,2,3), List(4,5,6), Map('a'->"x",'b'->"y")) But flatten will not work on following val l3 = List(1,2,3) val l4 = List(1,2,3,List('a','b')) val s1 = "hello world"

Recursively counting occurrences in a nested list of numbers

假装没事ソ 提交于 2019-12-13 16:26:53
问题 I'm finally getting around to recursion in Python and trying to count the number of occurrences of a target number in a list . However, I'm running into issues with counting occurrences in a nested list of numbers. For example def count(lst, target): if lst == []: return 0 if lst[0] == target: return 1 + count(lst[1:], target) else: return 0 + count(lst[1:], target) Output >>> count( [1,2,3,[4,5,5],[[5,2,1],4,5],[3]], 1 ) Output: 1 Expected output: 2 Is there an easy way to flatten nested

Concatenation of inner lists or ints [duplicate]

偶尔善良 提交于 2019-12-13 06:26:51
问题 This question already has answers here : Flattening a shallow list in Python [duplicate] (23 answers) Flatten an irregular list of lists (44 answers) Closed 6 years ago . I feel like I'm missing something obvious, but there it is... I would like to go from: lst = [[0, 1, 3, 7, 8, 11, 12], [8, 0, 1, 2, 3, 14], 2] to: output = [0, 1, 3, 7, 8, 11, 12, 8, 0, 1, 2, 3, 14, 2] I can do this with a for loop such as: output = [] for l in lst: if hasattr(l, '__iter__'): output.extend(l) else: output

Importing JSON data and flattening records / populating tables with PostgreSQL

被刻印的时光 ゝ 提交于 2019-12-13 03:55:17
问题 To begin, I'll refer to importing a JSON file in PostgreSQL. It's a neat way of importing JSON data and setting it in a database for further work. Here's a preview: The simplest way to import json from a file appear to not import a single json from a file but rather a single column csv: A list of one-line jsons: {"id": 23635,"name": "Jerry Green","comment": "Imported from facebook."} {"id": 23636,"name": "John Wayne","comment": "Imported from facebook."} then, under psql: create table t ( j

How to flatten a very complex XML into a new XML containing all nodes at root level

自古美人都是妖i 提交于 2019-12-12 23:57:14
问题 I am currently trying to flatten a large recurisve XML document, so that all the nested elements stay on root level but get an additional new attribute ("parent_id=...") to still keep the relations between the nodes. Each node has a lot of sub-nodes which i also need to grab, so the content has to stay the same. The file is very large (500k Rows - 33 MB in Size) Example XML: <product-catalog ...> <category id="1"> <content> ... </content> <category id="2"> <content> ... </content> </category>

How can I “merge”, “flatten” or “pivot” results from a query which returns multiple rows into a single result?

爱⌒轻易说出口 提交于 2019-12-12 10:35:39
问题 I have a simple query over a table, which returns results like the following: id id_type id_ref 2702 5 31 2702 16 14 2702 17 3 2702 40 1 2703 23 4 2703 23 5 2703 34 6 2704 1 14 And I would like to merge the results into a single row, for instance: id concatenation 2702 5,16,17,40:31,14,3,1 2703 23,23,34:4,5,6 2704 1:14 Is there any way to do this within a trigger? NB: I know I can use a cursor, but I would really prefer not to unless there is no better way. The database is Sybase version 12.5

Return flat object from sequelize with association

时光怂恿深爱的人放手 提交于 2019-12-12 03:29:31
问题 I am working on converting all my queries in sequelize. The problem I have come across is that when select queries include associations (ex. one to many), the object I get is an array of nested objects. It looks something like: [ { "field1": "someval", "field2": "someval1", "assoc_table": { "field_a": 1, "field_b": "someval" } }, { "field1": "someval", "field2": "someval3", "assoc_table": { "field_a": 5, "field_b": "someval" } }, { "field1": "someval", "field2": "someval3", "assoc_table": {

Flatten nested JSON (Dict, List) into List to prepare to write into DB

最后都变了- 提交于 2019-12-12 01:28:23
问题 I am still working on a problem to flatten a nested JSON file. The nested items are either List or Dict: Here is the file I want to flatten (Unlike in my previous post, I kept it at good length, but it only contains input[0] not any subsequent items as it will be very long): input = [{'states': ['USED'], 'niceName': '1-series', 'id': 'BMW_1_Series', 'years': [{'styles': [{'trim': '128i', 'states': ['USED'], 'submodel': {'body': 'Convertible', 'niceName': 'convertible', 'modelName': '1 Series