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 mysql.connector | |
mydb = mysql.connector.connect( | |
host='localhost', | |
user='root', | |
password='******', | |
#database='football_db' | |
) | |
print(mydb) |
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
del fList[0] | |
rows = '' | |
for i in range(len(fList)-1): | |
rows += "('{}','{}','{}','{}','{}','{}','{}','{}','{}','{}')"\ | |
.format(fList[i][0], fList[i][1], fList[i][2], fList[i][3], fList[i][4], | |
fList[i][5], fList[i][6], fList[i][7], fList[i][8], fList[i][9]) | |
if i != len(fList)-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
Creating the columns | |
Played = fList[0][0] | |
Team = fList[0][1] | |
GP = fList[0][2] | |
W = fList[0][3] | |
D = fList[0][4] | |
L = fList[0][5] | |
F = fList[0][6] | |
A = fList[0][7] |
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
filename = 'my_football_stats.csv' | |
f1 = open(filename, 'w') | |
headers = 'Number_of_Teams, Fewest_games_won, Highest_goals, Average_drawn_games \n' | |
f1.write(headers) | |
cursor.execute(''' SELECT COUNT(Team) AS Number_of_Teams, | |
min(W) AS Fewest_games_won, | |
max(F) AS Highest_goals, | |
avg(D) AS Average_drawn_games |
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 | |
import sqlalchemy | |
engine = sqlalchemy.create_engine('mysql+pymysql://root:****@localhost/football_db') | |
df = pd.read_sql_table('football', engine) | |
print(df.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
def color_negative_red(value): | |
if value < 0: | |
color = 'red' | |
elif value > 0: | |
color = 'green' | |
else: | |
color = 'black' | |
return 'color: %s' % color |
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 openpyxl | |
# newer xlsx file | |
df_2.to_excel('goals_game_stats.xlsx', index=False) |
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
players_data = pd.read_csv('player_data.csv', encoding='latin-1') | |
players_data.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
pd.set_option('display.max_columns', 60) | |
players_data.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 mysql.connector | |
mydb = mysql.connector.connect( | |
host='localhost', | |
user='root', | |
password='****', | |
database='football_db' | |
) | |
print(mydb) | |
print(players_data.columns) |