Home > Blockchain >  Interpolate return same ouput
Interpolate return same ouput

Time:11-13

There is the code:

x = np.array([2, 2.5, 3, 3.5, 3.75, 4, 4.5, 4.75, 5, 5.25, 5.5, 6])
y = np.array([5.197, 7.78, 11.14, 15.09, np.nan, 19.245, 23.11, np.nan, 26.25, np.nan, 28.6,30.3])
x.shape = (12, 1)
x.shape = (12, 1)
a = pd.DataFrame(x, y)
a.interpolate()
print(a)

And the output is the same, i have no idea what i do wrong.

5.197   2.00
7.780   2.50
11.140  3.00
15.090  3.50
NaN     3.75
19.245  4.00
23.110  4.50
NaN     4.75
26.250  5.00
NaN     5.25
28.600  5.50
30.300  6.00

CodePudding user response:

For new DataFrame is passed columns names in dictionary for avoid index from y, removed x.shape and output of interpolate is assigned back:

x = np.array([2, 2.5, 3, 3.5, 3.75, 4, 4.5, 4.75, 5, 5.25, 5.5, 6])
y = np.array([5.197, 7.78, 11.14, 15.09, np.nan, 19.245, 
              23.11, np.nan, 26.25, np.nan, 28.6,30.3])

a = pd.DataFrame({'a':x, 'b':y})
a = a.interpolate()
print(a)
       a        b
0   2.00   5.1970
1   2.50   7.7800
2   3.00  11.1400
3   3.50  15.0900
4   3.75  17.1675
5   4.00  19.2450
6   4.50  23.1100
7   4.75  24.6800
8   5.00  26.2500
9   5.25  27.4250
10  5.50  28.6000
11  6.00  30.3000
  • Related