Browse Source

Transférer les fichiers vers 'CODE'

master
t.briand 2 years ago
parent
commit
f66e500061
  1. 51
      CODE/corrtection_donnees.py
  2. 5
      CODE/modifications colonnes export csv.py

51
CODE/corrtection_donnees.py

@ -0,0 +1,51 @@
import csv
def correction_csv(nomdufichier):
csv_corrige = ''
with open(f'{nomdufichier}.csv', newline='', encoding='utf-8') as csvfile:
appariement_0 = csv.reader(csvfile, delimiter=' ')
for row in appariement_0:
ligne_brute =' '.join(str(elem) for elem in row)
ligne_brute = ligne_brute.replace("ê", "ê")
ligne_brute = ligne_brute.replace("é", "é")
ligne_brute = ligne_brute.replace('Ã\xa0', "à")
ligne_brute = ligne_brute.replace('è', "è")
ligne_brute = ligne_brute.replace('ô', "ô")
ligne_brute = ligne_brute.replace('û', "û")
ligne_brute = ligne_brute.replace('î', "î")
ligne_brute = ligne_brute.replace('â', "â")
ligne_brute = ligne_brute.replace('É', 'É')
ligne_brute = ligne_brute.replace('ç', 'ç')
csv_corrige = csv_corrige + ligne_brute + '\n'
print(ligne_brute)
fichier_txt=open(f"{nomdufichier}_correct_bis.csv","w", encoding='utf-8')
fichier_txt.write(csv_corrige)
fichier_txt.close()
# correction_csv('emissions')
# correction_csv('etablissements')
#correction_csv('Prelevements')
#correction_csv('Prod_dechets_dangereux')
# correction_csv('Prod_dechets_non_dangereux')
# correction_csv('Trait_dechets_dangereux')
# correction_csv('Trait_dechets_non_dangereux')
# correction_csv('tr_nap')
# correction_csv('tr_naf')
correction_csv('tr_code_effectif')
# correction_csv('te_siren_adresse')
# correction_csv('te_siren_admin')
# def remplacement_carac(nom_str):
# nom_str = nom_str.replace("ê", "ê")
# nom_str = nom_str.replace("é", "é")
# nom_str = nom_str.replace('Ã\xa0', "à")
# nom_str = nom_str.replace('è', "è")
# nom_str = nom_str.replace('ô', "ô")
# nom_str = nom_str.replace('û', "û")
# nom_str = nom_str.replace('î', "î")
# nom_str = nom_str.replace('â', "â")
# nom_str = nom_str.replace('É', 'É')

5
CODE/modifications colonnes export csv.py

@ -0,0 +1,5 @@
import pandas as pd
df = pd.read_csv('Prelevements.csv', delimiter = ';' ,usecols = ['identifiant','nom_etablissement','annee', 'prelevements_eaux_souterraines','prelevements_eaux_surface','prelevements_reseau_distribution','prelevements_mer'
])
print(df)
df.to_csv(r'C:\Users\totob\Desktop\Cours PSB\BDD SCRUM\UTF8\CSV finaux\prelevements.csv', index=False, sep=';')
Loading…
Cancel
Save