Creates a lookup dict from a Pandas DataFrame (tuples as keys / np as values)
Project description
Creates a lookup dict from a Pandas DataFrame (tuples as keys / np as values)
pip install a-pandas-ex-lookupdict
from a_pandas_ex_lookupdict import pd_add_lookup_dict
import pandas as pd
pd_add_lookup_dict()
df = pd.read_csv(
"https://raw.githubusercontent.com/pandas-dev/pandas/main/doc/data/titanic.csv"
)
di1 = df[:5].d_get_lookup_dict(as_index=["Name", "PassengerId"])
di2 = df[:5].d_get_lookup_dict(
as_values=["Cabin", "Fare"], as_index=["Name", "PassengerId"]
)
di1
Out[4]:
{('Braund, Mr. Owen Harris',
1): array([[0, 3, 'male', 22.0, 1, 0, 'A/5 21171', 7.25, nan, 'S']],
dtype=object),
('Cumings, Mrs. John Bradley (Florence Briggs Thayer)',
2): array([[1, 1, 'female', 38.0, 1, 0, 'PC 17599', 71.2833, 'C85', 'C']],
dtype=object),
('Heikkinen, Miss. Laina',
3): array([[1, 3, 'female', 26.0, 0, 0, 'STON/O2. 3101282', 7.925, nan, 'S']],
dtype=object),
('Futrelle, Mrs. Jacques Heath (Lily May Peel)',
4): array([[1, 1, 'female', 35.0, 1, 0, '113803', 53.1, 'C123', 'S']],
dtype=object)}
di2
Out[5]:
{('Braund, Mr. Owen Harris', 1): array([[nan, 7.25]], dtype=object),
('Cumings, Mrs. John Bradley (Florence Briggs Thayer)',
2): array([['C85', 71.2833]], dtype=object),
('Heikkinen, Miss. Laina', 3): array([[nan, 7.925]], dtype=object),
('Futrelle, Mrs. Jacques Heath (Lily May Peel)',
4): array([['C123', 53.1]], dtype=object)}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file a_pandas_ex_lookupdict-0.11.tar.gz
.
File metadata
- Download URL: a_pandas_ex_lookupdict-0.11.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2de445cc6c2efd5d95f90e0e8f5a2ec156600e1ea58d412f2555d4d38de2505a |
|
MD5 | f76b9bb0bd6e7e9f32dbe3749cbc0771 |
|
BLAKE2b-256 | c84e722fe54aca85ae5d6af978a870d6a2e92f3d91542a8b0454e98de5ef1633 |
File details
Details for the file a_pandas_ex_lookupdict-0.11-py3-none-any.whl
.
File metadata
- Download URL: a_pandas_ex_lookupdict-0.11-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d92f4bd19ff39a1c3d614f82ed85a3c3c5b2895bcbafebe6f55f4ce543279045 |
|
MD5 | d1752361ef650f86c0bede93c5f43b21 |
|
BLAKE2b-256 | a765f3a826d7bf1164cb2002b4bc419425723606f789c97ab30b4af089b1e045 |