My data becomes undefined any tips please?

Hello I’m trying to figure out what my Year data becomes undefined? Upon initial running of the cell the values appear by then after a few seconds becomes undefined?

First result on reshaping looks like this:

My data here:

casualties2014 = Array(10) [
  0: Object {Year: "2014", Pedestrians: "446", Pedal cyclists: "113", Motorcyclists: "339", Car occupants: "797", Other road users: "80", All road users: "1775", All road users (all severities) [note 6]: "194,477"}
  1: Object {Year: "2015", Pedestrians: "408", Pedal cyclists: "100", Motorcyclists: "365", Car occupants: "754", Other road users: "103", All road users: "1730", All road users (all severities) [note 6]: "186,189"}
  2: Object {Year: "2016", Pedestrians: "448", Pedal cyclists: "102", Motorcyclists: "319", Car occupants: "816", Other road users: "107", All road users: "1792", All road users (all severities) [note 6]: "181,384"}
  3: Object {Year: "2017", Pedestrians: "470", Pedal cyclists: "101", Motorcyclists: "349", Car occupants: "787", Other road users: "86", All road users: "1793", All road users (all severities) [note 6]: "170,993"}
  4: Object {Year: "2018", Pedestrians: "456", Pedal cyclists: "99", Motorcyclists: "354", Car occupants: "777", Other road users: "98", All road users: "1784", All road users (all severities) [note 6]: "160,597"}
  5: Object {Year: "2019", Pedestrians: "470", Pedal cyclists: "100", Motorcyclists: "336", Car occupants: "736", Other road users: "110", All road users: "1752", All road users (all severities) [note 6]: "153,158"}
  6: Object {Year: "2020", Pedestrians: "346", Pedal cyclists: "141", Motorcyclists: "285", Car occupants: "618", Other road users: "70", All road users: "1460", All road users (all severities) [note 6]: "115,584"}
  7: Object {Year: "2021", Pedestrians: "361", Pedal cyclists: "111", Motorcyclists: "310", Car occupants: "682", Other road users: "94", All road users: "1558", All road users (all severities) [note 6]: "128,209"}
  8: Object {Year: "2022", Pedestrians: "385", Pedal cyclists: "91", Motorcyclists: "350", Car occupants: "788", Other road users: "97", All road users: "1711", All road users (all severities) [note 6]: "135,480"}
  9: Object {Year: "2023", Pedestrians: "405", Pedal cyclists: "87", Motorcyclists: "315", Car occupants: "725", Other road users: "92", All road users: "1624", All road users (all severities) [note 6]: "132,977"}
  columns: Array(8) ["Year", "Pedestrians", "Pedal cyclists", "Motorcyclists", "Car occupants", "Other road users", "All road users", "All road users (all severities) [note 6]"]
]

The result:

reshapedCasualtiesData = Array(70) [
  0: Object {Year: undefined, RoadUserType: "Pedestrians", Count: 446}
  1: Object {Year: undefined, RoadUserType: "Pedal cyclists", Count: 113}
  2: Object {Year: undefined, RoadUserType: "Motorcyclists", Count: 339}
  3: Object {Year: undefined, RoadUserType: "Car occupants", Count: 797}
  4: Object {Year: undefined, RoadUserType: "Other road users", Count: 80}
  5: Object {Year: undefined, RoadUserType: "All road users", Count: 1775}
  6: Object {Year: undefined, RoadUserType: "All road users (all severities) [note 6]", Count: NaN}
  7: Object {Year: undefined, RoadUserType: "Pedestrians", Count: 408}
  8: Object {Year: undefined, RoadUserType: "Pedal cyclists", Count: 100}
  9: Object {Year: undefined, RoadUserType: "Motorcyclists", Count: 365}
  10: Object {Year: undefined, RoadUserType: "Car occupants", Count: 754}
  11: Object {Year: undefined, RoadUserType: "Other road users", Count: 103}
  12: Object {Year: undefined, RoadUserType: "All road users", Count: 1730}
  13: Object {Year: undefined, RoadUserType: "All road users (all severities) [note 6]", Count: NaN}
  14: Object {Year: undefined, RoadUserType: "Pedestrians", Count: 448}
  15: Object {Year: undefined, RoadUserType: "Pedal cyclists", Count: 102}
  16: Object {Year: undefined, RoadUserType: "Motorcyclists", Count: 319}
  17: Object {Year: undefined, RoadUserType: "Car occupants", Count: 816}
  18: Object {Year: undefined, RoadUserType: "Other road users", Count: 107}
  19: Object {Year: undefined, RoadUserType: "All road users", Count: 1792}

Seconds later:

I suspect the delete item.Year is the culprit. I would just filter it out of the entries before the map function and not delete it.

Hi Corbus thanks seems like something buggy was happening on my original notebook? I used both methods: Trialling different ways to remap the data / Suraj Rai | Observable and it reshaped the data.

I reattached my data source (CSV file) and it seems to be working as expected.

I reattached my data source (CSV file) and it seems to be working as expected.

Rerun the reshapedCasualtiesData2 cell and you will find that all years have disappeared from your data because the reshapedCasualtiesData cell mutates the cell value in casualties.

Cells don’t run in a deterministic order unless they depend on each other, so you may find that reshapedCasualtiesData2 can run before reshapedCasualtiesData and is thus able to still process the unmodified data.