From fd6035aba048fc4fac50ba4be7de7b28a9ad72ed Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 27 Feb 2024 13:37:32 +0100 Subject: [PATCH] pass numbers to string in pandas --- idhub/admin/forms.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/idhub/admin/forms.py b/idhub/admin/forms.py index cefc18b..2ee9d60 100644 --- a/idhub/admin/forms.py +++ b/idhub/admin/forms.py @@ -218,19 +218,22 @@ class ImportForm(forms.Form): data = self.cleaned_data["file_import"] self.file_name = data.name + if not self._schema: + return data + df = pd.read_excel(data) # convert dates to iso 8601 for col in df.select_dtypes(include='datetime').columns: df[col] = df[col].dt.strftime("%Y-%m-%d") + for col in df.select_dtypes(include=['number']).columns: + df[col] = df[col].astype(str) + data_pd = df.fillna('').to_dict() if not data_pd or df.last_valid_index() is None: self.exception("The file you try to import is empty!") - if not self._schema: - return data - for n in range(df.last_valid_index()+1): row = {} for k in data_pd.keys():