【问题标题】:how to set a variable dynamically - python, pandas如何动态设置变量 - python,pandas
【发布时间】:2016-10-23 01:55:53
【问题描述】:
>>>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”。

y = y0 + (y1-y0)*(x-x0/x1-x0)

如果 'mean' 值为 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,y1 位于 '0' 值之间时确定。
如何动态获取变量并计算?
你有设计程序的好主意吗?

【问题讨论】:

    标签: python csv pandas dynamic dataframe


    【解决方案1】:
    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]
    

    请原谅打字错误,在手机上工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-10-28
      • 2013-05-15
      • 1970-01-01
      • 2019-01-29
      • 2019-08-31
      • 2017-01-12
      • 2017-08-08
      • 1970-01-01
      相关资源
      最近更新 更多