Python Forum
looping calculation in dataframe
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
looping calculation in dataframe
#1
Hi,

I'm used to working with R but new to Python (except Think Python).
I wrote codes for various river cross section analysis in R and now want to transfer them to Python in order to compile them to executeables but I struggle with the first simple task:

I have a txt with the geometry as input (x being the lateral distance and y the elevation)

0,4
3,3
4,0
6,1
7,3
10,4

I want to calculate the area A for each step i: Ai= (yi+yi-1)*(xi-xi-1)/2

And store the value in a new column. How do I do this in Python? When storing x and y in seperate arrays, I'm struggling in adreessing them correctly in loops for example.
In R I could simply adress it i.e. data[i,1] or data[i-1,1]
Thank you Doh
Reply
#2
there are different ways, depending on what libraries you use. What have you tried? Do you use external libraries like pandas, or do you use just modules from python standard library like csv
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
I tried to go with numpy
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  DataFrame Calculation ian 2 3,665 Nov-22-2018, 12:10 AM
Last Post: SamSoftwareLtd

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020