Reading csv to array, performing linear regression on array and writing to csv in Python depending on gradient

微笑、不失礼 提交于 2019-12-07 18:07:29

I think you should be able to do this in a fairly simple script using glob to iterate through your files, and pandas to read in your data. Here is a basic outline of how I would structure it

import glob
import pandas as pd
for file in glob.glob('data/*'):
    df = pd.read_csv(file)
    for date, group in df.groupby(['year','month','day']:
        morning_data = group[group.HH24.between('09','12')]
        # calculate your linear regression here
        gradient, intercept = np.polyfit(morning_data.HH24,morning_data['wind speed'], 1)
        if gradient > 0 :
            print(gradient + "," + wind_direction + "," + gradient)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!