This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
booleans = [] | |
for result in Blast.Species_name_blast_hit: | |
if not re.search('bacterium', result): | |
booleans.append(True) | |
else: | |
booleans.append(False) | |
print(booleans[0:5]) | |
print(len(booleans)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Filtered = pd.Series(booleans) | |
New_blast_df = Blast[Filtered] | |
print(New_blast_df.shape) | |
print(New_blast_df) | |
Rows_removed = Blast.shape[0] - New_blast_df.shape[0] | |
print('The number of rows removed are: ' + str(Rows_removed)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df_2 = (Blast.Species_name_blast_hit.str.contains('bacterium') | |
# df_2 = Blast.Species_name_blast_hit.str.contains('neapuncta') | |
# a partial search is possible with the contains method | |
print(Blast[df_2]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
prem_table = pd.read_html('https://www.bbc.co.uk/sport/football/premier-league/table') | |
Premier_table = prem_table[0] | |
print(len(prem_table)) | |
print(type(prem_table)) | |
print(Premier_table.head(6)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Premier_table.columns | |
Index(['Unnamed: 0', 'Unnamed: 1', 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', | |
'Pts', 'Form'], | |
dtype='object') | |
Premier_league = Premier_table.drop(['Unnamed: 1'], axis=1) | |
Premier_league.head(6) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Table.drop(Table.tail(1).index, inplace=True) | |
Table.tail(3) | |
Table.shape | |
# Output | |
(20, 12) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Table.columns | |
Index(['Unnamed: 0', 'Team', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts', | |
'Form'], | |
dtype='object') | |
Table.rename(columns={'Unnamed: 0':'Position'}, inplace=True) | |
Table.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Table['Goals/game'] = round((Table.F / Table.P), 1) | |
Table['Goals conceded/game'] = round((Table['A'] / Table['P']), 1) | |
Table.sort_values(['Goals/game', 'Goal Ratio']).head(5) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prem = prem.drop(['Qualification or relegation'], axis=1) | |
prem['Points/Game'] = round(prem['Pts']/ prem['Pld'], 2) | |
prem['predicted season end point'] = prem['Points/game'] * 38 | |
prem = prem.sort_values(by='predicted season end point', ascending=False) | |
print(prem.head(10)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
goal_difference_ars_chel = prem.loc[3, 'GD'] - prem.loc[4, 'GD'] |