0

In my Python Code, I would also like Dakota with Hurricane, display appearances to show, in the Data Table, when run in Jupyter Notebook.

I typed the following modification to the Code, aiming to achieve this :-

(df['Spitfire'].str.contains('S', na=True))

Now the Dakota with Hurricane Display booking, i.e. in this case for Worthing - Display, that Data Displays, as does the Dakota Spitfire and Hurricane, and Dakota with Spitfire Display Bookings. But also the Solo Dakota Display bookings, which I don't want to display. What do I type to enable, that when Dakota = 'D' and 'Spitfire' = 'NaN' and 'Hurricane' = 'NaN', that Row is not displayed ?

I have almost managed, to sort out what I need to, in my Python code, for the 2007 Url, I just need, the Dakota with Hurricane bookings issue, sorting out Here is my Code, containing the relevant Url :-

import pandas as pd
import requests
from bs4 import BeautifulSoup

res = requests.get("http://web.archive.org/web/20070701133815/http://www.bbmf.co.uk/june07.html")
soup = BeautifulSoup(res.content,'lxml')
table = soup.find_all('table')[0]

df = pd.read_html(str(table))
df = df[1]
df = df.rename(columns=df.iloc[0])
df = df.iloc[2:]
df.head(15)

display = df[(df['Location'].str.contains('- Display')) & (df['Dakota'].str.contains('D')) & (df['Spitfire'].str.contains('S', na=True)) & (df['Lancaster'] != 'L')]     
display

Any help would be much appreciated.

Regards

Eddie

Edward Winch
  • 47
  • 2
  • 9

1 Answers1

0

You could query your display variable to refine the data:

display = display[~((display['Dakota'] == 'D') & (display["Spitfire"].isnull() & (display['Hurricane'].isnull())))]

where the ~ is used to negate the condition, so that the following query excludes elements from the DataFrame.

You can also include this in your original query on df.

user7217806
  • 2,014
  • 2
  • 10
  • 12
  • Hi user7217806, Many thanks for your very helpful reply. I sorted out what I wanted from this Thread, in the end. Could you look at my following latest Thread, and read all the posts and comments ? I need help with my latest Python Code. Your help would be very much appreciated. Here is the Thread Post Link :- https://stackoverflow.com/questions/57347179/i-want-to-filter-data-for-excel-files-using-pandas Regards Eddie Winch – Edward Winch Aug 31 '19 at 13:31
  • I very much appreciated your very useful reply )) – Edward Winch Aug 31 '19 at 13:37