PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, November 4, 2022

[FIXED] How to create a lambda function to return next cell value?

 November 04, 2022     lambda, pandas, python     No comments   

Issue

For example :

Val1 Val2
48 21
156 45
61 54
12 79
64 45

the excepted output is the followwing :

Val1 Val2 Output
48 21 45
156 45 54
61 54 79
12 79 45
64 45

What I did try is the following but it does not work and I am not sure if it is possible to do with lambda. ) )

DF["Output"] = DF.apply(lambda x: x[1].val2, axis=1)

The final goal is to apply thanks to a lambda function the following calculation :

(21/45) (45/54) (54/79) (79/45) ...

Wihtout having to create a new column with the shifted values as suggested in Ynjxsjmh Answer


Solution

Using Series.shift(-1)

DF["Output"] = DF["Val2"].shift(-1)


Answered By - Ynjxsjmh
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing