Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > fr.comp.lang.python > #3743
| From | yves <yves@free.fr.invalid> |
|---|---|
| Newsgroups | fr.comp.lang.python |
| Subject | Re: Projet Python : importation d'un dossier csv sous forme de matrice |
| Date | 2022-02-04 19:11 +0100 |
| Organization | Le serveur de jdd pour fr* |
| Message-ID | <87ee4imrif.fsf@l2> (permalink) |
| References | <l96dnV9hCoG-A2_8nZ2dnUU7_83NnZ2d@giganews.com> <61f3037b$0$8902$426a34cc@news.free.fr> <NaCdnRoVa4EBdWb8nZ2dnUU7_83NnZ2d@giganews.com> <87wniamtpp.fsf@l2> |
yves <yves@free.fr.invalid> writes:
> Effectivement, c'est inhabituel pour un format csv.
Sinon, Alain Ketterlin a donné une solution complète.
La base du traitement de ton fichier, c'est la méthode split() (googler
python split)
Un échantillon avec une chaîne de caractère s représentant ton fichier simplifié:
s = "0.00055 0.00008 0 ; 0.00085 0.00004 0.00007 ; 0.00010 0.00004 0.00006"
s1 = s.split(";")
print(s1)
>>> ['0.00055 0.00008 0 ', ' 0.00085 0.00004 0.00007 ', ' 0.00010 0.00004 0.00006']
for elt in s1:
print(elt.split())
['0.00055', '0.00008', '0']
['0.00085', '0.00004', '0.00007']
['0.00010', '0.00004', '0.00006']
Il a aussi utilisé une autre pythonnerie qui s'appelle la "list comprehension"
Exemple:
l1 = ['0.00010', '0.00004', '0.00006']
l2 = [ float(elt) for elt in l1]
print(l2)
>>> [0.0001, 4e-05, 6e-05]
--
Yves
Back to fr.comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar
Projet Python : importation d'un dossier csv sous forme de matrice Mand1n3 <nospam_playfairalikecestatut@outlook.com.invalid> - 2022-01-27 07:29 -0600
Re: Projet Python : importation d'un dossier csv sous forme de matrice yves <yves@free.invalid> - 2022-01-27 20:41 +0000
Re: Projet Python : importation d'un dossier csv sous forme de matrice mand1n3 <nospam_playfairalikecestatut@outlook.com.invalid> - 2022-02-03 08:37 -0600
Re: Projet Python : importation d'un dossier csv sous forme de matrice Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2022-02-03 19:45 +0100
Re: Projet Python : importation d'un dossier csv sous forme de matrice yves <yves@free.fr.invalid> - 2022-02-04 18:23 +0100
Re: Projet Python : importation d'un dossier csv sous forme de matrice yves <yves@free.fr.invalid> - 2022-02-04 19:11 +0100
Re: Projet Python : importation d'un dossier csv sous forme de matrice Olivier Miakinen <om+news@miakinen.net> - 2022-01-27 22:11 +0100
Re: Projet Python : importation d'un dossier csv sous forme de matrice K. <secwin88@yahoo.co.jp> - 2022-01-27 21:30 +0000
Re: Projet Python : importation d'un dossier csv sous forme de matrice K. <secwin88@yahoo.co.jp> - 2022-01-27 21:41 +0000
csiph-web