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

88
Vistas
Multiply only positive values within a column by 100

Any values greater than 0 should be multiplied by 100.

Example dataset:

df = pd.DataFrame({'col1': ['A','B','C'], 'col2':[-0.42,0.091,0.0023], 'col3': [30, 10,20]})

   col1     col2   col3
0     A    -0.42     30
1     B    0.091     10
2     C   0.0023     20

Expected outcome for col2 would look like this:

   col1     col2   col3
0     A    -0.42     30
1     B      9.1     10
2     C     0.23     20

Not sure how to tackle this one if anyone can provide coding or guidance using python/pandas

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

0

Use loc indexing:

df.loc[df['col2'] > 0, 'col2'] *= 100
print(df)

# Output:
  col1  col2  col3
0    A -0.42    30
1    B  9.10    10
2    C  0.23    20
over 4 years ago · Santiago Trujillo Denunciar

0

You can use np.where() to select 1 for each value if it's less than 0, and 100 for values greater than 0, and multiple the column by the resulting array:

df['col2'] *= np.where(df['col2'] > 0, 100, 1)

Output:

>>> df
  col1  col2  col3
0    A -0.42    30
1    B  9.10    10
2    C  0.23    20
over 4 years ago · Santiago Trujillo Denunciar

0

You can do like this:

df['col2'] = [row['col2'] if row['col2']<0 else row['col2']*100 for i,row in df.iterrows()]
over 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