Bonjour tous le monde,

Pour mon projet j'ai besoin de créer un fichier csv, afin d’utiliser pandas dans un deuxième temps.Quand j'essaye d'écrire il m'indique il y a 0 array .Alors que lorsque j'effectue un print il m'indique bien qu'il a y array.numpy (ligne 38).Pouvez vous de dire ou se trouve mon erreur ? Je vous remercie d'avances.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
import numpy as np
import matplotlib.pyplot as plt
import glob
import os.path
import csv
 
 
 
def tri1(lines):                    # creation de list 
	tab=[]
	for chn in lines:
		tab.append(chn.split('\t'))
	return(tab)
 
def change(nl,nc,tab):               # changement en float 
	A = A=np.arange(2,nc-1)   
	for lst in tab[1:nl]:
		for i in A:
			lst[i]=float(lst[i])
	#print(lst)
	return(lst)
 
 
def creation_dossier(chemin1):                            # creation d'un autre répertoire 
	os.mkdir(chemin1)	
 
def enregistrment_fichier(nom_de_fichier,matrice):
	np.savetxt(nom_de_fichier,matrice,delimiter =" ")
 
def affec(nl,tab):
 
	b1X=np.zeros(nl-1)                               # intilisation de matrice 
	b1Y=np.zeros(nl-1)
	b1Z=np.zeros(nl-1)
	AA=np.arange(1,nl)
	for k in AA:
		 b1X[k-1]=tab[k][2]                          # creation de matrice 
		 b1Y[k-1]=tab[k][3]
		 b1Y[k-1]=tab[k][4]
		 enregistrment_fichier("test_pour_valeur.csv",b1X[k-1])   # appel de la fonction 
		 savoir = type(b1X)
		 print(savoir)
 
 
 
 
def tri(rep):	                                        # fonction d'excution des taches 
 
	os.chdir(rep)
	for file in glob.glob("*.txt"):
		 test123 =open(file,"r")
		 lignes = test123.readlines()
		 tes1 = tri1(lignes)
		 modif = change(3,32,tes1)
		 trifinale = affec(3,tes1)
		 test123.close()
 
	return(tes1)
 
ter = tri("/media/tonny/TOSHIBA EXT/test_pour_stage/premier_test")
#ter1 = creation_fichier("/media/tonny/TOSHIBA EXT/test_pour_stage/premier_test/test_reper_1")
#print(b1X)
print("\n")
résultat :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
Traceback (most recent call last):
  File "test_forum.py", line 61, in <module>
    ter = tri("/media/tonny/TOSHIBA EXT/test_pour_stage/premier_test")
  File "test_forum.py", line 56, in tri
    trifinale = affec(3,tes1)
  File "test_forum.py", line 41, in affec
    enregistrment_fichier("test_pour_valeur.csv",b1X[k-1])   # appel de la fonction 
  File "test_forum.py", line 29, in enregistrment_fichier
    np.savetxt(nom_de_fichier,matrice,delimiter =" ")
  File "<__array_function__ internals>", line 6, in savetxt
  File "/home/tonny/.local/lib/python3.6/site-packages/numpy/lib/npyio.py", line 1395, in savetxt
    "Expected 1D or 2D array, got %dD array instead" % X.ndim)
ValueError: Expected 1D or 2D array, got 0D array instead