Skip to content

Instantly share code, notes, and snippets.

View StephenFordham's full-sized avatar

Stephen Fordham StephenFordham

View GitHub Profile
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))
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))
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])
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))
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)
@StephenFordham
StephenFordham / row_drop.py
Last active April 21, 2019 20:23
row_drop
Table.drop(Table.tail(1).index, inplace=True)
Table.tail(3)
Table.shape
# Output
(20, 12)
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()
@StephenFordham
StephenFordham / new_columns.py
Last active April 21, 2019 12:18
new_columns
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)
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))
goal_difference_ars_chel = prem.loc[3, 'GD'] - prem.loc[4, 'GD']