Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

468
Views
Cómo hacer restas rodantes repetidamente con Pandas Dataframe

¿Cómo hacer una resta rodante repetidamente con un marco de datos de Pandas?

Tengo un marco de datos que se ve así:

 value 100 1 4 10 5 3

Quiero restar repetidamente el valor anterior con el valor actual. Quiero el siguiente resultado:

 100 99 95 85 80 77

¿Cómo puedo hacer esto? Si tengo varias columnas en el marco de datos, ¿cómo puedo aplicar la misma operación a todas las columnas?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Una solución vectorizada:

 -(df['value']).cumsum() + df['value'].iat[0]*2

Producción:

 0 100 1 99 2 95 3 85 4 80 5 77 Name: value, dtype: int64
over 4 years ago · Santiago Trujillo Report

0

Combine la expanding con np.subtract.reduce :

 df.value.expanding(1).agg(np.subtract.reduce) 0 100.0 1 99.0 2 95.0 3 85.0 4 80.0 5 77.0 Name: value, dtype: float64
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!