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

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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 :- stackoverflow.com/questions/57347179/… Regards Eddie Winch
I very much appreciated your very useful reply ))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.