Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
D3 Trouble Altering Date

I'm importing a csv file and d3 treats every column as a string. The dates are currently stored like so: 2016-11-01. I'm trying to alter this column so that it will appear as Nov 16 (abbreviated month, abbreviated year).

Here is the code I have so far:

var dateParse = d3.timeParse("%Y-%m-%d") //matches the format in the csv
var monthParse = d3.timeParse("%m %y") //the format I'm looking for

var rowConverter = function (d) {
     return {
          date: dateParse(d.date)
          month: monthParse (d.date) //also tried monthParse(date)
     };
}

d3.dsv(",","my_csv.csv", rowConverter)

I expected this to give me two columns: one that would be the full date and one with the abbreviated month and year. I've confirmed the dateParse works correctly using console.log() statements. The monthParse, however, just results in NaNs. How can I get this column to populate correctly?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

d3.timeParse converts a string to a Date object. d3.timeFormat converts a Date object to a string.

You might be looking for something like this:

const dateParse = d3.timeParse("%Y-%m-%d");
const dateFormat = d3.timeFormat("%m %y");

function rowConverter(d) {
  const date = dateParse(d.date);
  return {
    date: date,
    month: dateFormat(date)
  };
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda