2016-06-21 91 views
1
>>>import pandas as pd 
>>>import numpy as np 
>>>from pandas import Series, DataFrame 

>>>rawData = pd.read_csv('wow.txt') 
>>>rawData 
    time  mean  
0 0.005   0     
1 0.010  258.64     
2 0.015  258.43     
3 0.020  253.72   
4 0.025   0     
5 0.030   0     
6 0.035  253.84    
7 0.040  254.17   
8 0.045   0     
9 0.050   0    
10 0.055   0  
11 0.060  254.73  
12 0.065  254.90  
      . 
      . 
      . 
489 4.180  167.46 

我想在公式下面应用,当我动态地输入'x'值来绘制一个图时,我会得到'y'。如何动态设置变量 - python,pandas

Y = Y0 +(Y1-Y0)*(X-X0/X1-X0)

如果 '意味' 值是0(例如index4,5 index8,9,10)
1)询问“你想插入吗?” 2)如果是,输入'x'值
3)使用公式计算(重复1-3直到答案为否)
4)如果回答为否,则结束程序。

 time(x-axis) mean(y-axis)   
0 0.005     0     
1 0.010   258.64     
2 0.015   258.43     
3 0.020 <--x0  253.72  <-- y0   
4 0.025     0     
5 0.030     0     
6 0.035 <--x1  253.84  <-- y1   
7 0.040 <--x0  254.17  <-- y0    
8 0.045     0     
9 0.050     0    
10 0.055     0  
11 0.060 <--x1  254.73  <-- y1 
12 0.065   254.90  
      . 
      . 
      . 
489 4.180   167.46 

变量X0,X1,Y0,它们位于外值 '0' 之间当确定Y1。
如何动态地获得一个变量,计算?
你有什么好主意来设计程序?

回答

0
for i in df.index: 
    if df.mean [i]=0: 
     answer=input ("Do you want to interpolate?") 
     if answer="Y": 
      x1 = df.loc[df.mean > 0].index[1] 
      y1 = df.loc[df.time > 0].index[1] 
      Interpolate eqn 
     else: 
      Process 
    else: 
     x0 = df.time [i] 
     y0 = df.mean[i] 

打扰打字,使用手机。