简体   繁体   中英

Removing Unwanted Data in Juypter Notebook

i was trying to plot a graph and after adding in the code to adjust the x axis label. There are tons of data shown despite me not calling up for them. Is there any way I can either improve my code to remove these set of data? (To be more specific: the whole column that appears as "None")

Codes as below:

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]

Screenshot below: 在此处输入图像描述

Replace

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

by

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

In Jupyter or in python prompt. The first one will display the list. So the output that you see. I added the variable dummy to disable this behavior. Since the variable is not useful it can be have any name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM