简体   繁体   English

如何在Bluemix中使用to_csv

[英]How to_csv in Bluemix

We have a dataframe we are working it in a ipython notebook. 我们有一个数据帧,我们正在ipython笔记本中使用它。 Granted, if one could save a dataframe in such a way that the whole group could have access to it through their notebooks, would be ideal, and I'd love to know how to do that. 当然,如果一个人能够以这样的方式保存数据帧,使整个组可以通过他们的笔记本访问它,那将是理想的,我很想知道如何做到这一点。 However could you help with the following specific problem? 但是,您可以帮助解决以下具体问题吗?

When we do df.to_csv("Csv file name") it appears that it is located in the exact same place as the files we placed in object storage to utilize in the ipython notebook. 当我们执行df.to_csv("Csv file name")它看起来与我们放置在ipython笔记本中的对象存储中的文件位于完全相同的位置。 However, when one goes to Manage Files, it's nowhere to be found. 但是,当一个人去管理文件时,它无处可寻。

When one runs pd.DataFrame.to_csv(df) , text of the csv file is apparently given. 当运行pd.DataFrame.to_csv(df) ,显然给出了csv文件的文本。 However when one copies that into a text editor (ex- Sublime text), saves it at a csv, and attempts to read it in to a dataframe, the expected dataframe is not yielded. 但是,如果将其复制到文本编辑器(ex-Sublime文本)中,将其保存在csv中,并尝试将其读入数据帧,则不会产生预期的数据帧。

How does one export a dataframe to csv format, and then access it? 如何将数据帧导出为csv格式,然后访问它?

I'm not familiar with bluemix, but it sounds like you're trying to save a pandas dataframe in a way that all of your collaborators can access and it look the same way for everyone. 我不熟悉bluemix,但听起来你正试图以一种所有协作者都可以访问的方式保存熊猫数据框,并且每个人看起来都是一样的。

Maybe saving and reading from CSVs is messing up the formatting of your dataframe. 也许从CSV中保存和读取会破坏数据帧的格式。 Have you tried using pickling ? 你尝试过用酸洗吗? Since pickling is based around python, it should give consistent results. 由于酸洗是基于python,它应该给出一致的结果。

Try this: 尝试这个:

import pandas as pd
pd.to_pickle(df, "/path/to/pickle/My_pickle")

and on the read side: 在阅读方面:

df_read = pd.read_pickle("/path/to/pickle/My_pickle")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM