Esempio n. 1
0
 def get_metadata_and_save(self, request, *args, **kwargs):
     uploadedFile = request.data['file']
     delimiter = get_delimiter(uploadedFile.name)
     df = pd.DataFrame(pd.read_csv(uploadedFile, sep=delimiter))
     column_headers = list(df.columns.values)
     num_rows = len(df.index)
     serializer = RequesterInputFileSerializer(data=request.data)
     if serializer.is_valid():
         id = serializer.create()
         metadata = {'id': id, 'num_rows': num_rows, 'column_headers': column_headers}
         return Response({'metadata': metadata})
     else:
         return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Esempio n. 2
0
 def create(self, **kwargs):
     uploaded_file = self.validated_data['file']
     batch_file = BatchFile(file=uploaded_file)
     delimiter = get_delimiter(uploaded_file.name)
     df = pd.DataFrame(pd.read_csv(uploaded_file, sep=delimiter, encoding='utf-8'))
     df = df.where((pd.notnull(df)), None)
     column_headers = list(df.columns.values)
     num_rows = len(df.index)
     first_row = dict(zip(column_headers, list(df.values[0])))
     batch_file.number_of_rows = num_rows
     batch_file.column_headers = column_headers
     batch_file.first_row = first_row
     batch_file.name = uploaded_file.name
     batch_file.save()
     return batch_file
 def get_metadata_and_save(self, request, *args, **kwargs):
     uploadedFile = request.data['file']
     delimiter = get_delimiter(uploadedFile.name)
     df = pd.DataFrame(pd.read_csv(uploadedFile, sep=delimiter))
     column_headers = list(df.columns.values)
     num_rows = len(df.index)
     serializer = RequesterInputFileSerializer(data=request.data)
     if serializer.is_valid():
         id = serializer.create()
         first_row = dict(zip(column_headers, list(df.values[0])))
         metadata = {
             'id': id,
             'num_rows': num_rows,
             'column_headers': column_headers,
             'first': first_row
         }
         return Response({'metadata': metadata})
     else:
         return Response(serializer.errors,
                         status=status.HTTP_400_BAD_REQUEST)
 def parse_csv(self):
     delimiter = get_delimiter(self.file.name)
     df = pd.DataFrame(pd.read_csv(self.file, sep=delimiter))
     df = df.where((pd.notnull(df)), None)
     return df.to_dict(orient='records')
Esempio n. 5
0
 def parse_csv(self):
     delimiter = get_delimiter(self.file.name)
     df = pd.DataFrame(
         pd.read_csv(self.file, sep=delimiter, encoding='utf-8'))
     df = df.where((pd.notnull(df)), None)
     return df.to_dict(orient='records')
Esempio n. 6
0
 def parse_csv(self):
     delimiter = get_delimiter(self.file.name)
     df = pd.DataFrame(pd.read_csv(self.file, sep=delimiter))
     return df.to_dict(orient='records')
Esempio n. 7
0
 def parse_csv(self):
     delimiter = get_delimiter(self.file.name)
     df = pd.DataFrame(pd.read_csv(self.file, sep=delimiter))
     return df.to_dict(orient='records')