ipython

How to preview a part of a large pandas DataFrame, in iPython notebook?

南笙酒味 提交于 2019-12-30 00:27:12
问题 I am just getting started with pandas in the IPython Notebook and encountering the following problem: When a DataFrame read from a CSV file is small, the IPython Notebook displays it in a nice table view. When the DataFrame is large, something like this is ouput: In [27]: evaluation = readCSV("evaluation_MO_without_VNS_quality.csv").filter(["solver", "instance", "runtime", "objective"]) In [37]: evaluation Out[37]: <class 'pandas.core.frame.DataFrame'> Int64Index: 333 entries, 0 to 332 Data

python 参数定义库argparse

血红的双手。 提交于 2019-12-29 19:58:05
python 参数定义库argparse 这一块的官方文档在 这里 注意到这个库是因为argparse在IDE中和在ipython notebook中使用是有差异的,习惯了再IDE里面用,转到ipython中会报错,究其原因,还是对库的本质不够理解。 打开argparse.py,里面有很多class,但是,实际笨妞貌似只用过ArgumentParser。ArgumentParser是用来创建argparse类的。 一般的应用过程是这样的: import argparse parser = argparse.ArgumentParser(description='Process some integers.') parser.add_argument('integers', metavar='N', type=int, nargs='+', help='an integer for the accumulator') parser.add_argument('--sum', dest='accumulate', action='store_const', const=sum, default=max, help='sum the integers (default: find the max)') args = parser.parse_args() print(args

python pandas conditional cumulative sum

孤街醉人 提交于 2019-12-29 07:33:11
问题 Consider my dataframe df data data_binary sum_data 2 1 1 5 0 0 1 1 1 4 1 2 3 1 3 10 0 0 7 0 0 3 1 1 I want to calculate the cumulative sum of data_binary within groups of contiguous 1 values. The first group of 1 's had a single 1 and sum_data has only a 1 . However, the second group of 1 's has 3 1 's and sum_data is [1, 2, 3] . I've tried using np.where(df['data_binary'] == 1, df['data_binary'].cumsum(), 0) but that returns array([1, 0, 2, 3, 4, 0, 0, 5]) Which is not what I want. 回答1: you

Can I make ipython exit from the calling code?

痞子三分冷 提交于 2019-12-29 06:54:08
问题 I have some code like this: form IPython import embed for item in my_item_list: embed() If I then run this program with python my_example_program.py on the first iteration through the loop I get put into an ipython shell and can inspect item and the environment as I would like to. On quitting ipython the loop resumes and then I can inspect the next item and the environment as you would expect. Is there a way for me to quit this code from within ipython (so that I am returned to a shell prompt

how to save the output of a cell in iPython notebook?

爷,独闯天下 提交于 2019-12-29 04:36:28
问题 I would like to be able to save the TEXT output of an iPython notebook cell into a file on disk. I have 2 additional requirements/requests: be able to re-run the cell and overwrite my output with whatever the latest is. also display the output within the notebook. I have figured out how to use the %%capture magic for some basic saving of an iPython notebook's cell into a file, but it does not seem flexible enough: it keeps appending every time I re-run the cell and I cannot get it to display

libpng version incompatibility in fresh installation of IPython

牧云@^-^@ 提交于 2019-12-29 03:38:06
问题 I used this guide to install the "scientific stack" for Python (OSX 10.9.2, brewed Python 2.7.6, IPython 2.0, matplotlib 1.3.1, libpng 1.6.10). Everything was looking good. However, trying to run a simple plot in IPython's notebook environment with --pylab=inline gives me this error: /usr/local/Cellar/python/2.7.6/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/core/formatters.py:239: FormatterWarning: Exception in image/png formatter: Could not create write

In a matplotlib figure window (with imshow), how can I remove, hide, or redefine the displayed position of the mouse? [duplicate]

大城市里の小女人 提交于 2019-12-28 17:31:22
问题 This question already has answers here : Interactive pixel information of an image in Python? (5 answers) Closed 4 years ago . I am using ipython with matplotlib, and I show images in this way: (started up with: ipython --pylab) figure() im = zeros([256,256]) #just a stand-in for my real images imshow(im) Now, as I move the cursor over the image, I see the location of the mouse displayed in the lower left corner of the figure window. The numbers displayed are x = column number, y = row number

Coloring Cells in Pandas

ぃ、小莉子 提交于 2019-12-28 11:56:27
问题 I am able to import data from an excel file using Pandas by using: xl = read_excel('path_to_file.xls', 'Sheet1', index_col=None, na_values=['NA']) Now that I have all the data in xl as DataFrame. I would like to colour some cells in that data based on conditions defined in another function and export the same (with colour coding) to an Excel file. Can someone tell me how should I go about this? Thank you. 回答1: Pandas has a relatively new Styler feature where you can apply conditional

How does IPython's magic %paste work?

廉价感情. 提交于 2019-12-28 08:02:36
问题 I want to copy already indented Python code / whole functions and classes into IPython. Everytime I try the indentation is screwed up and I get following error message: IndentationError: unindent does not match any outer indentation level (<ipython-input-23-354f8c8be51b>, line 12) If you want to paste code into IPython, try the %paste and %cpaste magic functions. 回答1: You can't copy to IPython directly. This are the steps: Copy the lines you want to copy into IPython into the clipboard Enter

Importing .py files in Google Colab

末鹿安然 提交于 2019-12-28 05:15:20
问题 Is there any way to upload my code in .py files and import them in colab code cells? The other way I found is to create a local Jupyter notebook then upload it to Colab, is it the only way? 回答1: You can save it first, then import it. from google.colab import files src = list(files.upload().values())[0] open('mylib.py','wb').write(src) import mylib Update (nov 2018): Now you can upload easily by click at [>] to open the left pane choose file tab click [upload] and choose your [mylib.py] import