Converts pandas DataFrames/Series into Iterator[tuple]
Project description
Converts pandas DataFrames/Series into Iterator[tuple]
pip install a-pandas-ex-to-tuple
from a_pandas_ex_to_tuple import pd_add_tuples
pd_add_tuples()
import pandas as pd
from pprint import pprint
df = pd.read_csv("https://github.com/pandas-dev/pandas/raw/main/doc/data/titanic.csv")
df = df[:5]
# DataFrame
t1 = tuple(df.ds_to_tuples(index=False, columns=True))
t2 = tuple(df.ds_to_tuples(index=True, columns=True))
t3 = tuple(df.ds_to_tuples(index=True, columns=False))
t4 = tuple(df.ds_to_tuples(index=False, columns=False))
pprint(t1)
pprint(t2)
pprint(t3)
pprint(t4)
# Series
t11 = tuple(df.Name.ds_to_tuples( index=False, columns=True))
t21 = tuple(df.Name.ds_to_tuples( index=True, columns=True))
t31 = tuple(df.Name.ds_to_tuples( index=True, columns=False))
t41 = tuple(df.Name.ds_to_tuples( index=False, columns=False))
pprint(t11)
pprint(t21)
pprint(t31)
pprint(t41)
(('PassengerId',
'Survived',
'Pclass',
'Name',
'Sex',
'Age',
'SibSp',
'Parch',
'Ticket',
'Fare',
'Cabin',
'Embarked'),
(1,
0,
3,
'Braund, Mr. Owen Harris',
'male',
22.0,
1,
0,
'A/5 21171',
7.25,
nan,
'S'),
(2,
1,
1,
'Cumings, Mrs. John Bradley (Florence Briggs Thayer)',
'female',
38.0,
1,
0,
'PC 17599',
71.2833,
'C85',
'C'),
(3,
1,
3,
'Heikkinen, Miss. Laina',
'female',
26.0,
0,
0,
'STON/O2. 3101282',
7.925,
nan,
'S'),
(4,
1,
1,
'Futrelle, Mrs. Jacques Heath (Lily May Peel)',
'female',
35.0,
1,
0,
'113803',
53.1,
'C123',
'S'),
(5,
0,
3,
'Allen, Mr. William Henry',
'male',
35.0,
0,
0,
'373450',
8.05,
nan,
'S'))
(('index',
'PassengerId',
'Survived',
'Pclass',
'Name',
'Sex',
'Age',
'SibSp',
'Parch',
'Ticket',
'Fare',
'Cabin',
'Embarked'),
(0,
1,
0,
3,
'Braund, Mr. Owen Harris',
'male',
22.0,
1,
0,
'A/5 21171',
7.25,
nan,
'S'),
(1,
2,
1,
1,
'Cumings, Mrs. John Bradley (Florence Briggs Thayer)',
'female',
38.0,
1,
0,
'PC 17599',
71.2833,
'C85',
'C'),
(2,
3,
1,
3,
'Heikkinen, Miss. Laina',
'female',
26.0,
0,
0,
'STON/O2. 3101282',
7.925,
nan,
'S'),
(3,
4,
1,
1,
'Futrelle, Mrs. Jacques Heath (Lily May Peel)',
'female',
35.0,
1,
0,
'113803',
53.1,
'C123',
'S'),
(4,
5,
0,
3,
'Allen, Mr. William Henry',
'male',
35.0,
0,
0,
'373450',
8.05,
nan,
'S'))
((0,
1,
0,
3,
'Braund, Mr. Owen Harris',
'male',
22.0,
1,
0,
'A/5 21171',
7.25,
nan,
'S'),
(1,
2,
1,
1,
'Cumings, Mrs. John Bradley (Florence Briggs Thayer)',
'female',
38.0,
1,
0,
'PC 17599',
71.2833,
'C85',
'C'),
(2,
3,
1,
3,
'Heikkinen, Miss. Laina',
'female',
26.0,
0,
0,
'STON/O2. 3101282',
7.925,
nan,
'S'),
(3,
4,
1,
1,
'Futrelle, Mrs. Jacques Heath (Lily May Peel)',
'female',
35.0,
1,
0,
'113803',
53.1,
'C123',
'S'),
(4,
5,
0,
3,
'Allen, Mr. William Henry',
'male',
35.0,
0,
0,
'373450',
8.05,
nan,
'S'))
((1,
0,
3,
'Braund, Mr. Owen Harris',
'male',
22.0,
1,
0,
'A/5 21171',
7.25,
nan,
'S'),
(2,
1,
1,
'Cumings, Mrs. John Bradley (Florence Briggs Thayer)',
'female',
38.0,
1,
0,
'PC 17599',
71.2833,
'C85',
'C'),
(3,
1,
3,
'Heikkinen, Miss. Laina',
'female',
26.0,
0,
0,
'STON/O2. 3101282',
7.925,
nan,
'S'),
(4,
1,
1,
'Futrelle, Mrs. Jacques Heath (Lily May Peel)',
'female',
35.0,
1,
0,
'113803',
53.1,
'C123',
'S'),
(5,
0,
3,
'Allen, Mr. William Henry',
'male',
35.0,
0,
0,
'373450',
8.05,
nan,
'S'))
(('Name',),
('Braund, Mr. Owen Harris',),
('Cumings, Mrs. John Bradley (Florence Briggs Thayer)',),
('Heikkinen, Miss. Laina',),
('Futrelle, Mrs. Jacques Heath (Lily May Peel)',),
('Allen, Mr. William Henry',))
(('index', 'Name'),
(0, 'Braund, Mr. Owen Harris'),
(1, 'Cumings, Mrs. John Bradley (Florence Briggs Thayer)'),
(2, 'Heikkinen, Miss. Laina'),
(3, 'Futrelle, Mrs. Jacques Heath (Lily May Peel)'),
(4, 'Allen, Mr. William Henry'))
((0, 'Braund, Mr. Owen Harris'),
(1, 'Cumings, Mrs. John Bradley (Florence Briggs Thayer)'),
(2, 'Heikkinen, Miss. Laina'),
(3, 'Futrelle, Mrs. Jacques Heath (Lily May Peel)'),
(4, 'Allen, Mr. William Henry'))
(('Braund, Mr. Owen Harris',),
('Cumings, Mrs. John Bradley (Florence Briggs Thayer)',),
('Heikkinen, Miss. Laina',),
('Futrelle, Mrs. Jacques Heath (Lily May Peel)',),
('Allen, Mr. William Henry',))
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_to_tuple-0.10.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e3b8b54d662c55d2a7524932a185021161dee16b804f9032fb67d9bf1a474806 |
|
MD5 | ad2f8c573709a8bf93d8a87b253da366 |
|
BLAKE2b-256 | aa812e3cab9f5789fca1ce17c6ab108b3bb9f9354f60c2e563545f6247cc1385 |
Close
Hashes for a_pandas_ex_to_tuple-0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c9ac9dcbbf57adb374f43e79e0a898a0b0978b876696eb9737bcb0f9608b8e49 |
|
MD5 | 860f8d7bdb8620999c8d7655a7b428a1 |
|
BLAKE2b-256 | ec57ac4ad0d9df86fef2278ad44a61ec33699d62150e2f517c5b78164abe7e55 |