From 284ac6c00ae53baa435d589b69751f5f292df3b1 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Wed, 4 Oct 2017 08:18:49 +0200 Subject: o Adding DigikeyRepository.to_pandas(). --- src/ee/digikey/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py index 957aa40..d1664e2 100644 --- a/src/ee/digikey/__init__.py +++ b/src/ee/digikey/__init__.py @@ -115,6 +115,16 @@ class DigikeyProduct(object): attributes[key] = value return c + def _to_pandas_dict(self): + value = { + "MPN": self.mpn, + "Digi-Key": self.part_number, + "URL": self.url, + } + for a in self.attributes: + value[a.attribute_type.label] = a.value + return value + from_ini_r = re.compile("([^/]*)/(.*)") @staticmethod @@ -362,3 +372,10 @@ class DigikeyRepository(object): for p in self.products: if p.mpn == mpn: return p + + def to_pandas(self): + import pandas + + data = [part._to_pandas_dict() for part in self.products] + index = [part.mpn for part in self.products] + return pandas.DataFrame(data=data, index=index) -- cgit v1.2.3