I'm setting up a dataframe by reading a csv file in pandas, the columns represent points in one dimensional positional arguments for different samples, the rows each represent 0.01s time segments. I want to create a new dataframe to represent velocity and acceleration (so basically apply the operation [point(i)-point(i-1)]/0.01) to every cell in the data frame.

I'm having trouble using pandas.applymap or other approaches because I don't quite know how to refer to multiple arguments in the dataframe for every operation, if that makes sense.

    import pandas as pd
    import numpy as np

    data = pd.read_csv("file_name")
    def velocity(xf, xi):
        v = (xf - xi)*100
        return v

    velocity = data.applymap(velocity)

This is what the first few column and rows of the original data frame look like:

    X LFHD   Y LFHD   Z LFHD   X RFHD   Y RFHD
0  700.003 -1769.61  1556.05  811.922 -1878.46
1  699.728 -1769.50  1555.99  811.942 -1878.14
2  699.465 -1769.38  1555.99  811.980 -1877.81
3  699.118 -1769.38  1555.83  812.005 -1877.48
4  699.017 -1768.78  1556.19  812.003 -1877.11

For every positional value in each column, I want to calculate the velocity where the initial positional value is the cell above (xi as the input in the velocity function) and the final positional value is the cell in question (xf).

when I try to run the above code, it gives me an error because there is only one argument provided for velocity, when it expects 2. I don't know how to go about providing the second argument so that it outputs the proper new dataframe with the velocity calculated in each cell.

1 Answers

0
KRKirov On
df_velocity = data.diff()*100

df_velocity
Out[6]: 
   X_LFHD  Y_LFHD  Z_LFHD  X_RFHD  Y_RFHD
0     NaN     NaN     NaN     NaN     NaN
1   -27.5    11.0    -6.0     2.0    32.0
2   -26.3    12.0     0.0     3.8    33.0
3   -34.7     0.0   -16.0     2.5    33.0
4   -10.1    60.0    36.0    -0.2    37.0