diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-10-04 08:18:49 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-10-04 08:18:49 +0200 |
commit | 284ac6c00ae53baa435d589b69751f5f292df3b1 (patch) | |
tree | 535ae4afd84820c3e8d26cf039287e37a49ca9b4 /src/ee/digikey | |
parent | b735e67fef864b675d86a33eb8409d379bd62307 (diff) | |
download | ee-python-284ac6c00ae53baa435d589b69751f5f292df3b1.tar.gz ee-python-284ac6c00ae53baa435d589b69751f5f292df3b1.tar.bz2 ee-python-284ac6c00ae53baa435d589b69751f5f292df3b1.tar.xz ee-python-284ac6c00ae53baa435d589b69751f5f292df3b1.zip |
o Adding DigikeyRepository.to_pandas().
Diffstat (limited to 'src/ee/digikey')
-rw-r--r-- | src/ee/digikey/__init__.py | 17 |
1 files changed, 17 insertions, 0 deletions
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) |