Back
Close

Computing with Data

elgeish
33.1K views

Shelving

Shelves is a module that provides persistent dictionary objects whose values can be any Python object that can be pickled.

import shelve
# Example 1 - store
patients_df = {
"age" : [25.2, 35.4, 52.1],
"height" : [68.1, 62.5, 60.5],
"weight" : [170.2, 160.7, 185.5]
}
records = shelve.open('patients')
records['patients'] = patients_df
records.close()
# Example 2 - load and manipulate
records = shelve.open('patients')
patients_reconstructed = records['patients']
del records['patients'] # delete value from disk
records.close()
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants