0
我想創建一個小程序,它允許我使用Python中的raw_input
(現在只是輸入)函數將一組數字輸入到OLS函數中如何使用輸入或raw_input創建輸入到OLS程序
目前,我有代碼看起來像這樣
import pandas as pd
from pandas import DataFrame
from pandas.stats.api import ols
inp=raw_input("Enter String A")
A=map(int,inp.split())
inp=raw_input("Enter String B")
B=map(int,inp.split())
inp=raw_input("Enter String C")
C=map(int,inp.split())
def firstreg():
df = pd.DataFrame({'A':[A], 'B':[B], 'C':[C]})
reg = ols (y=df['A'], x=df[['B','C']])
print reg
firstreg()
正如你看到的我是想用A=map(int,inp.split())
來解決我的問題。它沒有工作。我也用A=array(inp)
和A=float(inp)
和A=str(inp)
嘗試和解決我的問題都無濟於事。主要問題是OLS函數是Pandas需要輸入的字符串才能工作。
我想有這樣的程序運行:
運行該文件regression.py
它要求輸入字符串一個
- 用戶輸入他們的一組數字或者作爲「1,2,3等...」或者「1 2 3等...」
- 然後用戶對做同樣的處理Enter String B和輸入字符串C。
- 然後該程序打印出基於該OLS模型迴歸結果中
def firstreg():
我希望這個問題是有道理的。