In [7]:
from functional import seq
import pandas as pd

In [3]:
!ls


PyFunctional-pandas-tutorial.ipynb  chat_logs.jsonl  users.db
camping_purchases.csv		    gear_list.txt    users.json

In [28]:
# Data file this notebook works with
cat camping_purchases.csv


1,tent,300
2,food,100
3,shoes,200
4,sleeping bag, 350
5,stove,100
6,backpack,200
7,sunscreen,15
8,plates,10

In [23]:
# Load the initial data using pandas, possibly do some work in pandas
df = pd.read_csv('camping_purchases.csv', header=None)
df


Out[23]:
0 1 2
0 1 tent 300
1 2 food 100
2 3 shoes 200
3 4 sleeping bag 350
4 5 stove 100
5 6 backpack 200
6 7 sunscreen 15
7 8 plates 10

In [24]:
# This shows PyFunctional using the dataframe correctly.
# PyFunctional also detects the notebook environment and that the data is table like
# so renders a nice HTML table representation.
seq(df)


Out[24]:
1tent 300
2food 100
3shoes 200
4sleeping bag350
5stove 100
6backpack 200
7sunscreen 15
8plates 10

In [25]:
# Turning this into a list can see that the sequence is a list of rows.
# They are arrays since that is how pandas outputs lists of rows
seq(df).list()


Out[25]:
[array([1, 'tent', 300], dtype=object),
 array([2, 'food', 100], dtype=object),
 array([3, 'shoes', 200], dtype=object),
 array([4, 'sleeping bag', 350], dtype=object),
 array([5, 'stove', 100], dtype=object),
 array([6, 'backpack', 200], dtype=object),
 array([7, 'sunscreen', 15], dtype=object),
 array([8, 'plates', 10], dtype=object)]

In [26]:
# Show representation using PyFunctional's csv parsing
seq.csv('camping_purchases.csv')


Out[26]:
1tent 300
2food 100
3shoes 200
4sleeping bag 350
5stove 100
6backpack 200
7sunscreen 15
8plates 10

In [27]:
# PyFunctional doesn't try to parse the columns, perhaps an area for improvement
seq.csv('camping_purchases.csv').list()


Out[27]:
[['1', 'tent', '300'],
 ['2', 'food', '100'],
 ['3', 'shoes', '200'],
 ['4', 'sleeping bag', ' 350'],
 ['5', 'stove', '100'],
 ['6', 'backpack', '200'],
 ['7', 'sunscreen', '15'],
 ['8', 'plates', '10']]

In [ ]: