pandas.DataFrame.to_pickle向后兼容性

时间:2017-08-17 01:45:24

标签: python-2.7 pandas pickle

在pandas 0.20中引入了

<!DOCTYPE html> <html> <head> <style> * { box-sizing: border-box; } #myInput { background-image: url('/css/searchicon.png'); background-position: 10px 10px; background-repeat: no-repeat; width: 100%; font-size: 16px; padding: 12px 20px 12px 40px; border: 1px solid #ddd; margin-bottom: 12px; } #myTable { border-collapse: collapse; width: 100%; border: 1px solid #ddd; font-size: 18px; } #myTable th, #myTable td { text-align: left; padding: 12px; } #myTable tr { border-bottom: 1px solid #ddd; } #myTable tr.header, #myTable tr:hover { background-color: #f1f1f1; } </style> </head> <body> <h2>Number search</h2> <input type="text" id="myInput" onkeyup="myFunction()" placeholder="Search for names.." title="Type in a name"> <table id="myTable"> <tr class="header"> <th style="width:60%;">Number</th> <th style="width:60%;">Name</th> <th style="width:60%;">ID</th> </tr> <tr> <td>905-373-3333</td> <td>Mike</td> <td>4563</td> </tr> <tr> <td>905-333-3333</td> <td>adam</td> <td>8963</td> </tr> <tr> <td>416-373-3432</td> <td>Jim</td> <td>9363</td> </tr> </table> <script> function myFunction() { var input, filter, table, tr, td, i, cleanedFilter; input = document.getElementById("myInput"); filter = input.value.toUpperCase(); table = document.getElementById("myTable"); tr = table.getElementsByTagName("tr"); cleanedFilter = filter.replace("-",""); for (i = 0; i < tr.length; i++) { td = tr[i].getElementsByTagName("td")[0]; if (td) { cellContent = td.innerHTML.toUpperCase().replace(/-/g,""); if (cellContent.indexOf(cleanedFilter) > -1) { tr[i].style.display = ""; } else { tr[i].style.display = "none"; } } } } </script> </body> </html> 的压缩参数。 https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_pickle.html

在pandas 0.20之前,我没有需要指定的压缩参数。

我有一个使用pandas 0.18编写的webapp并使用版本0.18中的pandas.read_pickle读取pickle文件而没有错误,我应该如何挑选文件?

到目前为止,我已尝试将压缩参数设置为无和&#39; gzip&#39;。两个都不工作。

1 个答案:

答案 0 :(得分:2)

看起来您实际上并不需要指定。默认compression='infer'应该有效。

但是,为什么不只是进口和使用泡菜?

这就是我一直在使用的

# import and save object as pickle
import pickle
pickle.dump(object, open('filename.pkl', 'wb'))

# and this is how to load them
loaded_object = pickle.load(open('filename.pkl', 'rb'))