現在下記のようなコードを使用しています。ここではux_data.csvから読み込んだ時系列の値に対して様々な平均処理をしているだけです。
import pandas as pd measurement_x = pd.read_csv('../ux_data.csv') #データの読み込み measurement_x['Time'] = pd.to_datetime(measurement_x['Time']) measurement_x['Ux'] = measurement_x['Ux'].astype(float) average_1s = measurement_x.groupby(pd.Grouper(key="Time", freq="1S")).mean().dropna() print(average_1s) average_1s.to_csv('Ux_1s.csv')
ux_data.csvは
Time,Ux 8:30:00,0.0491646 8:30:00,0.04885409 8:30:00,0.04976679 8:30:00,0.04826003 8:30:00,0.04794893 8:30:00,0.05098768 8:30:00,0.05143833 8:30:00,0.05202135 8:30:00,0.05379565 8:30:01,0.05515847 8:30:01,0.05621742 8:30:01,0.05601825 8:30:01,0.05550477 8:30:01,0.05656208 8:30:01,0.0586561 8:30:01,0.05779947 8:30:01,0.05558534 8:30:01,0.05220271 8:30:01,0.04816291 8:30:01,0.04559563 8:30:02,0.04275988 8:30:02,0.03971009 8:30:02,0.03749207 8:30:02,0.03499524 8:30:02,0.03329378
やりたいこと
じつは他にもuy_data.csvとuz_data.csvというデータがあってそれぞれにも同じ処理をしています。しかし、わざわざ元データを3つのファイル(ux_data.csvとuy_data.csvとuz_data.csv)に分割して、それぞれコードを流しているという状況ですが、これがめんどくさいので、どうにか元データのcsvファイルもそれの処理をするpythonのスクリプトも1つのファイルに統合したいと思っています。
つまり下記のようなcsvファイルを読み込んで、1列目Ux、2列目Uy、3列目Uzに対してそれぞれに処理を行えるコードを書きたいです。
Time,Ux,Uy,Uz 8:30:00,0.0491646,-0.0002001,0.00402596 8:30:00,0.04885409,-0.002383158,0.003770471 8:30:00,0.04976679,-0.003475622,0.005422015 8:30:00,0.04826003,-0.004453839,0.003875185 8:30:00,0.04794893,-0.001935884,0.003395008 8:30:00,0.05098768,-0.003536097,0.004372599 8:30:00,0.05143833,-0.001048134,0.003362806 8:30:00,0.05202135,-0.001461966,0.002990205 8:30:00,0.05379565,-0.003538994,0.003346398 8:30:01,0.05515847,-0.005891384,0.002454313 8:30:01,0.05621742,-0.007940515,0.002544694 8:30:01,0.05601825,-0.006490421,0.00287806 8:30:01,0.05550477,-0.009249165,0.002430463 8:30:01,0.05656208,-0.008241333,0.0024078 8:30:01,0.0586561,-0.009167475,0.00279996 8:30:01,0.05779947,-0.006925913,0.001816961 8:30:01,0.05558534,-0.003440346,0.002140206 8:30:01,0.05220271,-0.004212458,0.002945417 8:30:01,0.04816291,-0.005834663,0.002247226 8:30:01,0.04559563,-0.002735651,0.002552841 8:30:02,0.04275988,-0.005105641,0.002515985 8:30:02,0.03971009,-0.004192282,0.00194344 8:30:02,0.03749207,0.002352139,0.002638657 8:30:02,0.03499524,-0.00077876,0.00223753 8:30:02,0.03329378,0.003363156,0.001549597 8:30:02,0.03151985,0.005747369,0.002091152 8:30:02,0.0309383,0.006082963,0.001903451 8:30:02,0.02998217,0.002782575,0.001573171
分からないこと
上記のファイルを読み込んで、どうやって特定の1列ずつを抽出して処理ができるのか
です。
どなたかご教授してくれませんか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。