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 | |
premier_table = pd.read_html('https://en.wikipedia.org/wiki/2018%E2%80%9319_Premier_League') | |
print(len(premier_table)) | |
#Output | |
20 |
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 = premier_table[4] | |
print(prem.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
prem['GD'] = pd.to_numeric(['GD'], errors='coerce') |
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
def remove_pos_neg(goal_diff): | |
if goal_diff.startswith('+') or goal_diff.startswith('-'): | |
n = goal_diff[1:] | |
else: | |
n = goal_diff | |
return n | |
assert remove_pos_neg('+64') == '64' | |
assert remove_pos_neg('-16') == '16' | |
assert remove_pos_neg('65') == '65' |
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['GD'] = prem['GD'].apply(remove_pos_neg) | |
print(prem.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
import pandas as pd | |
A = pd.read_csv('query_sequences.csv') | |
B = pd.read_csv('Sequence_reference.csv') | |
print(A.columns) | |
print(B.columns) | |
Output: | |
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
my_unknown_id = A['Unknown_sample_no'].tolist() | |
my_unknown_seq = A['Unknown_sample_seq'].tolist() | |
Reference_species = B['Reference_sequences_ID'].tolist() | |
Reference_sequences = B['Reference_sequences'].tolist() |
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
Ref_dict = dict(zip(Reference_species, Reference_sequences)) | |
Unknown_dict = dict(zip(my_unknown_id, my_unknown_seq)) | |
print(Ref_dict) | |
print(Unknown_dict) | |
Output: | |
{'A': 'AAAAGCGCGAGGGGGGA', 'K': 'GGGAGAGAGGG', 'Y': 'CGGAGCGTTT', 'T': 'TTTTAGAGAGCTCTG', 'P': 'TAGAGAGCGGCC', 'E': 'GAAGGCGCT', 'V': 'TATAGCGCGCG', 'M': 'TAGAGCGCGA', 'N': 'GGCTCCGG | |
GAGA', 'Q': 'GGGGCCCCCATA'} |
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 | |
filename = 'seq_match_compare.csv' | |
f = open(filename, 'w') | |
headers = 'Query_ID, Query_Seq, Ref_species, Ref_seq, Match, Match start Position\n' | |
f.write(headers) | |
for ID, seq in Unknown_dict.items(): | |
for species, seq1 in Ref_dict.items(): |
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
f = open('Premier_league.csv') | |
fString = f.read() | |
fList = [] | |
for line in fString.split('\n'): | |
fList.append(line.split(',')) | |
print(fList) | |
Output: |