创建迭代DataFrame列表的不同pickle文件

时间:2016-10-25 19:16:36

标签: python-3.x pandas dataframe pickle

我正在尝试编写一个函数,该函数将从包含DataFrames的列表中编写pickle文件。我想迭代该列表,并从每个DataFrame创建一个具有不同文件名的不同pickle文件。我写过这个函数:

def picklecreator(dflist):
a=1
for b in dflist:
    b.to_pickle('filename_' + str(a) + '.pkl')
    a=+1

return 1

此功能仅创建第一个pickle文件' filename_1.pkl'如何使其适用于列表中的所有DataFrame?

2 个答案:

答案 0 :(得分:0)

你可以这样做:

def picklecreator(dflist):
    for i, b in enumerate(dflist):
        b.to_pickle(r'd:/temp/filename_{:02d}.pkl'.format(i+1))
    return 1

但我会使用HDF商店 - 它更灵活,更方便。

演示:

def save_dflist_hdfs(dflist, file_name_ptrn='d:/temp/data_{:02}.h5', **kwarg):
    for i, df in enumerate(dflist):
        df.to_hdf(file_name_ptrn.format(i+1), 'df{:02d}'.format(i+1), **kwarg)
    return len(dflist)    

然后你可以这样称呼它:

save_dflist_hdfs(dflist, r'd:/temp/data_{:02}.h5', format='t',
                 complib='blosc', complevel=5)

答案 1 :(得分:0)

我认为问题出在代码 <div class="col-md-3"> <div class="form-group"> <label for="Sale">Product On Sale?</label> <input type="checkbox" id="Editsale" name="Editsale" class="checkbox checkboxsize"> </div> </div> <div id="EditsalePrice" style="display:none"> <div class="col-sm-3"> <div class="form-group"> <label for="">Sale Price</label> <input type="text" name="Editsale_price" id="Editsale_price" placeholder="Enter Product Sale Price" class="form-control"> </div> </div> </div> 上。您应该改写<?php class bank { public $holders_firstName = "Aadil"; public $holders_lastName = "Hafesji"; public $holders_currentNumber = 456789111; public $holders_aaCode = "20-55-66"; public $holders_b = "£8"; } class check { $obj = new check; echo $obj->holders_firstName; } class save { // } ?>