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
Close
Hashes for a_pandas_ex_lookupdict-0.10.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffdbdadde4343cc34f6a602ca7ae149af93a4ce7877968480d1a39d73cd325f0 |
|
MD5 | 9f75cd46eb00cbf000e281259160d375 |
|
BLAKE2b-256 | bbad91cc190382ea467eb64d201c9c70fd6729179d51a10dde5a9bda7752eb93 |
Close
Hashes for a_pandas_ex_lookupdict-0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12dff853a4d2a85643f9b9aed325629bb87cd5848f687a56e5156107de78d396 |
|
MD5 | fb16023e2b1b3d9c08b2b84cb9204536 |
|
BLAKE2b-256 | 9813e7fd33f0a277fe6b9eba5dd87a42a1c6c6897c1fef2cfaa94182286b880d |