我创建了6个不同的数据框,以消除其原始数据框的异常值。现在,我试图在同一图形上绘制所有消除异常值的数据框。
这是我的代码,消除了每个数据帧中的异常值:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
plt.style.use("ggplot")
#---Original DataFrame
x = (g[0].time[:27236])
y = (g[0].data.f[:27236])
df = pd.DataFrame({'Time': x, 'Data': y})
#----Removes the outliers in a given DataFrame and plots a graph
newdf = df.copy()
newdf = df[~df.groupby('Data').transform( lambda x: abs(x-x.mean()) > 1.96*x.std()).values]
#newdf.plot('Time', 'Data')
#---Original DataFrame
x = (q[0].time[:47374])
y = (q[0].data.f[:47374])
df = pd.DataFrame({'Time': x, 'Data': y})
#----Removes the outliers in a given DataFrame and plots a graph
newdf = …Run Code Online (Sandbox Code Playgroud)