np.array表示单列数据帧

时间:2017-09-29 17:09:57

标签: python pandas numpy

我有一个2列数组,我计算其平均值(从而创建列A)。我希望能够引用和操作列A,但似乎无法将其保存为新的单列。这是我的具体示例,'过滤'是我希望能够保存/使用/错误定期ValueError: Wrong number of items passed 2, placement implies 1

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

df=pd.read_csv('/Users/myfile.csv', delimiter=',', usecols=['Time','Distance'])

x = df['Time']
y = df['Distance']

n = 25  #small n = less smoothed

fwd = pd.Series.ewm(df,span=n, adjust=True).mean()
bwd = pd.Series.ewm(df[::-1],span=n, adjust=True).mean()
filtered = np.stack(( fwd, bwd[::-1] ))
filtered2 = np.mean(filtered, axis=0)
plt.subplot(2,1,1)
plt.title('smoothed and raw data')
plt.plot(x,y, color = 'orange')
plt.plot(x,filtered, color='green')
plt.plot(x,fwd, color='red')
plt.plot(x[::-1],bwd, color='blue')
plt.xlabel('time')
plt.ylabel('distance')

df['filtered2'] = pd.DataFrame(filtered, dtype='str', index=None)
print(filtered2)

smoothed_velocity = ((df.filtered2 - df.filtered2.shift(1)) /  df['Time'] - df['Time'].shift(1))

print(smoothed_velocity)
plt.subplot (2,1,2)
plt.title ('smoothed velocity')
plt.plot (smoothed_velocity, color = 'orange')

plt.tight_layout()
plt.show()

因为我定义'过滤'两次,我尝试将一个变为另一个变量而没有运气。提供的错误是ValueError: x and y must have same first dimension, but have shapes (458,) and (2, 458, 2)

任何帮助都是rad!

0 个答案:

没有答案
相关问题