diff --git a/lire_csv_2.ipynb b/lire_csv_2.ipynb new file mode 100644 index 0000000..fd06cca --- /dev/null +++ b/lire_csv_2.ipynb @@ -0,0 +1,138 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "import csv\n", + "import os\n", + "import matplotlib.pyplot as plt\n", + "import numpy as np\n", + "import pandas as pd\n", + "import numpy as np\n", + "import pandas as pd\n", + "import matplotlib.pyplot as plt\n", + "from sklearn.datasets import make_blobs\n", + "from sklearn.metrics import accuracy_score\n", + "import plotly.graph_objects as go\n", + "import PySimpleGUI as sg\n", + "from os import listdir" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "def selection_fichier(dossier):\n", + " # Liste des fichiers dans le répertoire\n", + " nom_fichiers = listdir(dossier)\n", + " # Créer une liste de tuples pour les options de la liste déroulante\n", + " options = [(fichier) for fichier in nom_fichiers]\n", + " # Créer la disposition de l'interface graphique\n", + " layout = [\n", + " [sg.Text(\"Sélectionnez les fichiers à traiter :\")],\n", + " [sg.Listbox(values=options, select_mode=sg.LISTBOX_SELECT_MODE_EXTENDED, size=(40, 10))],\n", + " [sg.Button(\"OK\"), sg.Button(\"Annuler\")]\n", + " ]\n", + " # Créer la fenêtre de l'interface graphique\n", + " window = sg.Window(\"Sélection des fichiers\", layout)\n", + " # Attendre que l'utilisateur interagisse avec l'interface graphique\n", + " while True:\n", + " event, values = window.read()\n", + " if event == sg.WINDOW_CLOSED or event == \"Annuler\":\n", + " fichiers_selectionnes = []\n", + " break\n", + " elif event == \"OK\":\n", + " fichiers_selectionnes = values[0]\n", + " break\n", + " # Fermer la fenêtre de l'interface graphique\n", + " window.close()\n", + " return fichiers_selectionnes" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [], + "source": [ + "def lire_un_fichier_csv(data):\n", + " \n", + " tableau_2D=[]\n", + " tab=[]\n", + " with open(data,\"r\") as csv_file:\n", + " csv_reader=csv.reader(csv_file,delimiter=',')\n", + " for ligne in csv_reader:\n", + " tableau_2D.append(ligne)\n", + " for i in range(len(tableau_2D[0])):\n", + " ligne = [] \n", + " for j in range(len(tableau_2D)):\n", + " ligne.append(float(tableau_2D[j][i]))\n", + " tab.append(ligne) \n", + " return tab" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [], + "source": [ + "def lire_fichier_csv(data,fichier):\n", + " resultat=[]\n", + " tableau=[]\n", + " for i in fichier:\n", + " tableau=lire_un_fichier_csv(os.path.join(data,i))\n", + " resultat.append(tableau)\n", + " return resultat" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Shear_x001-x101_y010_Rot00.csv']\n", + "-20.0\n" + ] + } + ], + "source": [ + "# Répertoire contenant les fichiers\n", + "dossier = \"dataverse_files\\Dataset\\Shear_Wave_Rot00_CSV_Data\"\n", + "fichiers_selectionnes=selection_fichier(dossier)\n", + "print(fichiers_selectionnes)\n", + "tableau_3D=lire_fichier_csv(dossier,fichiers_selectionnes)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}