How to get indexes of values ​​in a Pandas DataFrame?

I am sure that there should be a very simple solution to this problem, but I can not find it (and looking through the previously asked questions, I did not find the answer I wanted or did not understand).

I have a dataframe similar to this (much larger, with many other rows and columns):

      x   val1   val2   val3
0    0.0  10.0   NaN    NaN
1    0.5  10.5   NaN    NaN
2    1.0  11.0   NaN    NaN
3    1.5  11.5   NaN  11.60
4    2.0  12.0   NaN  12.08
5    2.5  12.5  12.2  12.56
6    3.0  13.0  19.8  13.04
7    3.5  13.5  13.3  13.52
8    4.0  14.0  19.8  14.00
9    4.5  14.5  14.4  14.48
10   5.0  15.0  19.8  14.96
11   5.5  15.5  15.5  15.44
12   6.0  16.0  19.8  15.92
13   6.5  16.5  16.6  16.40
14   7.0  17.0  19.8  18.00
15   7.5  17.5  17.7    NaN
16   8.0  18.0  19.8    NaN
17   8.5  18.5  18.8    NaN
18   9.0  19.0  19.8    NaN
19   9.5  19.5  19.9    NaN
20  10.0  20.0  19.8    NaN

dVal/dx ( 3 , , ). - NaN , x val . , , val notnull. . , , ( , , , , :)).

(, , , , , , , ):

import pandas as pd
import numpy as np

df = pd.read_csv('H:/DocumentsRedir/pokus/dataframe.csv', delimiter=',')

vals = list(df.columns.values)[1:]

for i in vals:
    V = np.asarray(pd.notnull(df[i]))

    mask = pd.notnull(df[i])
    X = np.asarray(df.loc[mask]['x'])

    derivative=np.diff(V)/np.diff(X)

:

ValueError: operands could not be broadcast together with shapes (20,) (15,) 

, -, notnull...

, , , ? !

( : np.diff ? numpy.)

+4
1

dVal/dX:

dVal = df.iloc[:, 1:].diff()  # `x` is in column 0.
dX = df['x'].diff()
>>> dVal.apply(lambda series: series / dX)

    val1  val2  val3
0    NaN   NaN   NaN
1      1   NaN   NaN
2      1   NaN   NaN
3      1   NaN   NaN
4      1   NaN  0.96
5      1   NaN  0.96
6      1  15.2  0.96
7      1 -13.0  0.96
8      1  13.0  0.96
9      1 -10.8  0.96
10     1  10.8  0.96
11     1  -8.6  0.96
12     1   8.6  0.96
13     1  -6.4  0.96
14     1   6.4  3.20
15     1  -4.2   NaN
16     1   4.2   NaN
17     1  -2.0   NaN
18     1   2.0   NaN
19     1   0.2   NaN
20     1  -0.2   NaN

( ), - , X.

+3

Source: https://habr.com/ru/post/1649101/


All Articles