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

122
Vistas
Find column index by searching column header of a Dataset in Apache Spark Java

I have a Spark Dataset similar to the example below:

       0         1                  2          3
    +------+------------+--------------------+---+
    |ItemID|Manufacturer|       Category     |UPC|
    +------+------------+--------------------+---+
    |   804|         ael|Brush & Broom Han...|123|
    |   805|         ael|Wheel Brush Parts...|124|
    +------+------------+--------------------+---+

I need to find the position of a column by searching the column header.

For Example:

int position=getColumnPosition("Category");

This should return 2.

Is there any Spark function supported on Dataset<Row> datatype to find the column index or any java functions which can run on Spark dataset?

about 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You need to access the schema and read the field index as follows:

int position = df.schema().fieldIndex("Category");
about 4 years ago · Santiago Trujillo Denunciar

0

I have used index attribute for lists:

df.columns.index(column_name)
about 4 years ago · Santiago Trujillo Denunciar

0

You can consider this option (Scala implementation):

def getColumnPosition(dataframe: DataFrame, colName: String): Int = {
    dataframe.columns.indexOf(colName)
}
about 4 years ago · Santiago Trujillo 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