x=45
y=34
x+y
mynames="dhafer"
print(mynames)
print('My name is',mynames,"and I'm",x+y," years old")
Comparaisons
5==3
4==4
8!=4
8>3
i=0
while i<10:
print("you have a message")
i= i+1
range(10)
for i in range(10):
print(i**3)
def hello():
print("Hello ESSAI")
hello()
def add_numbers(a,b):
print((a+b)/2)
add_numbers(4,9)
Check if a number is odd or even
def even_check(a):
if a%2==0:
print("It's even")
else:
print("It's odd")
even_check(9)
list1=["A","B","C","D","F"]
list2=[2,4,10]
list1[0]
list2[1]
list1[0:3]
list1+list2
import pandas as pd
import glob
print(glob.glob("*.csv"))
print(glob.glob("*.html"))
decat=pd.read_csv('decathlon.csv')
decat
decat['100m']
decat.describe()
decat.Competition
decat.Javeline
Let us first write a function that searchs xls files in a given forlder
import os, fnmatch
def find(pattern, path):
result = []
for root, dirs, files in os.walk(path):
for name in files:
if fnmatch.fnmatch(name, pattern):
result.append(os.path.join(root, name))
return result
cwd = os.getcwd()
cwd
find("*.xlsx",'/Users/dhafermalouche/Documents/Teaching_2018_2019/Teaching_python')
fxls = pd.ExcelFile("/Users/dhafermalouche/Documents/Teaching_2018_2019/Teaching_python/migration.xlsx")
fxls
How to know the names of the sheets in your new imported xlsx file?
nsheets=fxls.sheet_names
nsheets
Load the sheet 'Données'
fxls_donnees= fxls.parse(2)
fxls_donnees