Не получается двигать(
accumulator[currentValue] = data[currentValue][0] до data[currentValue][5]
должно получиться
[
{ state: "Ohio", year: 2000, pop: 1.5 },
{ state: "Ohio", year: 2001, pop: 1.7 },
...
], из {
state: ["Ohio", "Ohio", "Ohio", "Nevada", "Nevada", "Nevada"],
year: [2000, 2001, 2002, 2001, 2002, 2003],
pop: [1.5, 1.7, 3.6, 2.4, 2.9, 3.2],
}
const pandas = {
DataFrame: function ({ data, columns }) {
return !Array.isArray(data) && !data.length
? Object.keys(data).reduce(
(accumulator, currentValue, currentIndex, array) => {
accumulator[currentValue] = data[currentValue][currentIndex];
return accumulator;
},
{}
)
: data;
},
};
const data = {
state: ["Ohio", "Ohio", "Ohio", "Nevada", "Nevada", "Nevada"],
year: [2000, 2001, 2002, 2001, 2002, 2003],
pop: [1.5, 1.7, 3.6, 2.4, 2.9, 3.2],
};
const frame1 = pandas.DataFrame({
data,
});
const frame2 = pandas.DataFrame({
data: [
{ state: "Ohio", year: 2000, pop: 1.5 },
{ state: "Ohio", year: 2001, pop: 1.7 },
],
});
//console.log(frame1['state']);
//console.log(frame1['year']);
//console.log(frame1['pop']);
console.log(frame1); //{ state: 'Ohio', year: 2001, pop: 3.6 } не перебирает