Skip to content

Instantly share code, notes, and snippets.

View StephenFordham's full-sized avatar

Stephen Fordham StephenFordham

View GitHub Profile
import mysql.connector
mydb = mysql.connector.connect(
host='localhost',
user='root',
password='******',
#database='football_db'
)
print(mydb)
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:
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]
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
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())
def color_negative_red(value):
if value < 0:
color = 'red'
elif value > 0:
color = 'green'
else:
color = 'black'
return 'color: %s' % color
import openpyxl
# newer xlsx file
df_2.to_excel('goals_game_stats.xlsx', index=False)
@StephenFordham
StephenFordham / excel_to_pandas_DataFrame.py
Created May 13, 2019 17:20
excel_to_pandas_DataFrame
players_data = pd.read_csv('player_data.csv', encoding='latin-1')
players_data.head()
@StephenFordham
StephenFordham / all_columns.py
Last active May 13, 2019 17:43
all_columns
pd.set_option('display.max_columns', 60)
players_data.head()
import mysql.connector
mydb = mysql.connector.connect(
host='localhost',
user='root',
password='****',
database='football_db'
)
print(mydb)
print(players_data.columns)