删除 Jupyter Notebook 中不需要的数据

Removing Unwanted Data in Juypter Notebook

我试图绘制图表,并在添加代码后调整 x 轴标签。尽管我没有调用它们,但仍显示了大量数据。有什么办法可以改进我的代码以删除这些数据集? (更具体地说:显示为“None”的整个列)

代码如下:

DataFrame:
q3 = c.execute('''
SELECT Month AS Month, 
   Year AS Year, 
   COUNT(*) AS TotalFlights,
   Dest AS Destination
FROM ontime
WHERE ontime.Cancelled = 0 AND
  Destination = 'ABE' OR Destination = 'CSG' OR Destination = 'HLN' OR Destination = 'LAW' 
GROUP BY Dest, Month, Year
ORDER BY Dest ASC, Year ASC, Month ASC
''').fetchall()
q3 = pd.DataFrame (q3, columns = 
['Month','Year','TotalFlights','Destination'])
pd.DataFrame(q3)

Combining Month and Year:
q3["Month"] = q3["Month"].astype(str)
q3["Year"] = q3["Year"].astype(str)
q3['Month_Year'] = q3["Month"] + '/' + q3["Year"]


Plotting of Graph:
>>> g = sns.FacetGrid(data=q3, col="Destination", col_wrap=2, height=6)
>>> g = g.map(plt.plot, "Month_Year", "TotalFlights", marker=".")
>>> [plt.setp(ax.get_xticklabels(), rotation=45) for ax in g.axes.flat]

截图如下:

替换

[plt.setp(ax.get_xticklabels(), rotation=45) for ax in g.axes.flat]

来自

dummy=[plt.setp(ax.get_xticklabels(), rotation=45) for ax in g.axes.flat]

在 Jupyter 或 python 提示符中。第一个将显示列表。所以你看到的输出。我添加了变量 dummy 来禁用此行为。由于变量没有用,它可以有任何名称。