Python Forum
Trying to Tabulate Information from an Aircraft Website Link(s)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to Tabulate Information from an Aircraft Website Link(s)
#31
df['Location'].str.contains('Darley', regex=True, na=False)
Look at result.
df['Location'].str.contains('Darley|Boston', regex=True, na=False)
Now see True False values.

Wrap slicing operation to see result,as we have done in the multiply Boolean check before.
df[df['Location'].str.contains('Darley|Boston', regex=True, na=False)]
str.contains can take regex as specify to be clear with regex=True .
In regex | means or.
>>> import re
>>> 
>>> s = 'foobar'
>>> re.findall(r'foo', s)
['foo']

>>> re.findall(r'foo|bar', s)
['foo', 'bar']
Reply
#32
Thanks for your help snippsat,

This is my current working Code:-
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')) & (df['Lancaster'] != 'L')]     
display 
For the 2004 BBMF Schedule, The Url is the Following :-

http://web.archive.org/web/2004102000013...dates.html

But the format is different, to the previous BBMF Year Schedules. Can you look at the Webpage, and suggest to me, what I need to change in my Code, to enable the same type of data, to be presented as in those Schedules ? Your help is much appreciated.

Reply
#33
(Jun-23-2019, 08:58 PM)eddywinch82 Wrote: But the format is different, to the previous BBMF Year Schedules. Can you look at the Webpage, and suggest to me, what I need to change in my Code
You have to look at the source code of new site an make changes.
Should keep away from new task in this Thread as it already long,and you most try yourself and post code.
So a last tips last for new site,you most do more accurate search for the table needed on that site.
import pandas as pd
import requests
from bs4 import BeautifulSoup

res = requests.get("http://web.archive.org/web/20041020000138/http://www.raf.mod.uk/bbmf/displaydates.html")
soup = BeautifulSoup(res.content,'lxml')
table = soup.find_all('table', align="CENTER")[0]
df = pd.read_html(str(table))

# Clean up,put index(Date location...) at top,delete 2 first row
df = df[0]
df = df.rename(columns=df.iloc[0])
df = df.iloc[2:]
df
Reply
#34
Many thanks snippsat for your help,

Also for the original and new Python Code, I would also like Dakota with Hurricane, display appearances to show,

I typed the following modification to the Code, aiming to achieve this :-
(df['Spitfire'].str.contains('S', na=True))
for the Original Code, with 'X' in place of the 'S', for the latest Python Code Version.

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' or 'X' (in the new Code), and 'Spitfire' = 'NaN' and 'Hurricane' = 'NaN', that Row is not displayed ?

I have almost managed, to sort out what I need to, this is the new code, for the 2004 Url :-

import pandas as pd
import requests
from bs4 import BeautifulSoup

res = requests.get("http://web.archive.org/web/20041020000138/http://www.raf.mod.uk/bbmf/displaydates.html")
soup = BeautifulSoup(res.content,'lxml')
table = soup.find_all('table', align="CENTER")[0]
df = pd.read_html(str(table))

df = df[0]
df = df.rename(columns=df.iloc[0])
df = df.iloc[2:]
df.head(15)

display = df[(df['Location'].str.contains('[a-zA-Z]')) & (df['Dakota'].str.contains('X')) & (df['Spitfire'].str.contains('X', na=True)) & (df['Lancaster'] != 'X')]    
display 
Any help would be appreciated

Regards

Eddie
Reply
#35
Can anyone help me ?
Reply
#36
(Jun-25-2019, 07:52 PM)eddywinch82 Wrote: Can anyone help me ?
Now are you up running and have gotten a lot help,new people would probably not look into this because it's a long Thread.
Again you ask a long question about a lot different cases you try to fit into one search.
I not gone look into this now,as this more a specif task you want solve and not me.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to insert Dashed Lines in between Rows of a tabulate output Mudassir1987 0 496 Sep-27-2023, 10:09 AM
Last Post: Mudassir1987
  pandas, tabulate, and alignment menator01 3 7,256 Feb-05-2022, 07:04 AM
Last Post: menator01
  display the result of Dataframe in tabulate format alex80 0 1,387 Sep-09-2020, 02:22 PM
Last Post: alex80
  How to tabulate correctly repeated blocks? Xiesxes 4 2,931 Mar-21-2020, 04:57 PM
Last Post: Xiesxes
  Obtain Geometric Information and name from a map-design website fyec 2 2,434 Aug-08-2018, 05:11 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020