How to retrieve help for Pandas methods using '??' - pandas

I am new to Pandas, trying to learn the basics from lecture videos. In one of these the presenter demonstrates that one can call help on methods using ??.
For example if I have loaded a dataframe df then typing df.getitem?? should print the docstring as well as the source code to the console. This would be really great to have but it doesn't work for me! I tried different variants of the command and also tried to find a comment online on this, without success.
What do I need to type in order to retrieve the docstring as well as the source code of a Pandas method? Thanks a lot for your help !
(I am using Python 3.5 and PyCharm in case that makes a difference)

I believe that your lecturer was using ipython as this does support dynamic object information. For instance this is the output in ipython when you do df.__getitem__?? you see the following:
I strongly recommend ipython for interactive python development, you'll find a lot of devs using this for data exploration and analysis, the workbook is really useful for saving your commands and the output

Related

Sublime text 3 Variable Explorer

I have searched through the whole internet and didn't find anything useful. Could please anyone suggest how to make a variable explorer in Sublime text 3 like in Spyder?
(Spyder maintainer here) If you want to create a representation of your current namespace (what is shown in the Variable Explorer), you can take a look at how we build it here, specially the value_to_display function, the one really responsible for that.
The viewers (for lists, dicts, Numpy arrays and DataFrames) are implemented in PyQt, and you can find them here.
To bring the value of a variable from a running IPython kernel and pass it to the viewers, we created our own kernel that serializes a value and sends it to Spyder. In Spyder we deserialize it and pass it to the Viewers here (look for the CreateEditor method).
The process is really more complex than this little explanation, but I hope you can get an idea of how it works.

python vincent map does not display

I'm trying to use vincent package to visualize my data (in pandas) in jupyter notebook, but have trouble in initial attempt ,here is the code I use (copied from the http://wrobstory.github.io/2013/10/mapping-data-python.html):
import vincent
import pandas
world_topo=r'world-countries.topo.json'
geo_data = [{'name': 'countries',
'url': world_topo,
'feature': 'world-countries'}]
vis = vincent.Map(geo_data=geo_data, scale=200)
vis.to_json('vega.json')
vis.display()
After I ran the code, nothing was displayed. I checked the type of the vis:
vincent.charts.Map
I'm not sure how to proceed here, I appreciate any input on this problem.
Not sure at which point of implementation of this you are.
Assuming you just used pip to install vincent and tried the code in PY IDLE , you might be missing 2 important steps:
AFIK vincent only generates jsons to be presented using Vega via Jupyter notebook.
To render with Vega You will need to install:
1) Jupyter and dependencies
2) Vega and dependencies
I was able to do so using these instructions.
Once jupiter launched, a window opens in the browser, I had to choose 'Python3' under 'new', and put code in the prompt on that page.
Alternately you can use this online Vega renderer. Please also see Vega docs
Note that it seems that vincent is not the latest technology for that purpose, their page points to Altair
Also, I noticed that the json that is generated in 'vega.json' from the code you posted, using the original data, does not render anywhere. That's also an issue, probably happens because it uses outdated format, but I am not sure.
I have limited experience with this technology but I was able to get graphs to render, specifically this, and it is also how it looked for me.
I know that this post is old but I found your error and I thought I would answer here to help future users of vincent as it has worked beautifully for me. I am working with the anaconda version of vincent and jupyter notebook.
First, you have to initialize vincent in your notebook
import vincent
vincent.core.initialize_notebook()
and your next problem is that your URL isn't actually pointing anywhere. For the world map topography you need:
world_topo="https://raw.githubusercontent.com/wrobstory/vincent_map_data/master/world-countries.topo.json"
A decent map printed out for me with those two exceptions.

What is a good workflow for developing Julia modules with IPython/Jupyter?

I find myself frequently developing new Julia modules while at the same time using those modules for my work. So I'll have an IPython (Jupyter) notebook, with something like:
using DataFrames
using MyModule
Then I'll do something like:
x = myfunction(7, 3)
But I'll have to modify that function, and unfortunately by that point I can't simply do
using MyModule
again. I'm not really sure why; I thought that calling using simply declares available modules in order to make the global scope aware of them, and then when a name is actually needed, the runtime searches for the definition among the currently loaded modules (starting with Main).
So shouldn't using MyModule simply just refresh the definitions of the items in the already declared module? Why do I have to completely stop and restart the kernel in order to use my updated functions? (Is it because names are bound only once to functions that are declared using the function keyword?)
I've looked at Julia Workflow Tips, but I don't find the whole Tmp, tst.jl system very simple or elegant... at least for a notebook.
Any suggestions?
I think there's a lot of truth in this statement attributed to one of the Juno developers: Jupyter notebook is for working with data. Juno IDE is for working with code.
Jupyter is great for using modules in a notebook style that the output you're getting is reproducible. Juno and the REPL have less overhead that let you keep starting new sessions (faster testing, and fixes the problem you noted), have multiple tabs open to follow code around a complex module, and can use the debugger (in v0.5). They address different development issues for difference stages of use. I think you're pushing against the tide if you're using the wrong tool for the wrong job.

build pandas documentation from source using installed pandas rather than an inplace build

My question is: How can I use my up to date pandas installation to build the pandas documentation?
I read the pandas/doc/README.rst, which says to navigate to the pandas/doc directory and run python make.py html. Unfortunately, this does not work for me as it seems to require having first done an inplace build of pandas. My (windows) computer does not have the necessary prerequisites for doing a development build, and it seems to be an unnecessary burden when I just want to add some notes that improve the documentation.
The background for why I am asking this question is that earlier this week I posted a SO question about pandas hdf5 output. In discussing the answer with Jeff, he encouraged me to add some commentary to the documentation. So I forked the pandas repository and began to think about how I would add to the documentation. I am not interested in setting up a development build of the complete pandas installation. I would like to be able to modify the documentation, build it, and see my changes before submitting a pull request. Is there a reasonable way to do this?
Thanks!
Here are the pandas contributing guidelines & howto's.

Using QT Designer to create TableView to Postgres Database

I'm creating a plugin in Quantum GIS that is using Postgres as the back end and QT Designer to make the GUI. I'm using psycopg2 to run scripts in the database and even fetch results of queries to set the values of labels in the GUI. This stuff is working fine for me.
What I would like to do now after some queries are run by clicking a 'calculate' button is for the resulting table to be shown in the plugin as a TableView. I know there widget exists expressly for the purpose of viewing tables but I can't quite figure out how to go about it. I'm not sure if I should be using psycopg2 or PySide, since most examples I have seen online use the latter.
I am wondering if someone can tell me which between psycopg2 and PySide should be used to create the TableView. Second, I am wondering what the 'signal' should be to the TableView widget to display the results of a query in Postgres. Lastly, is anyone can offer some instruction as to how to set up the code it would be hugely appreciated!
Cheers,
Roman
I've gone ahead and tried following the PyQt documentation, but as it's provided in C++ and I'm only a beginner programmer using Python I'm not sure if I've caught all the necessary amendments to the code syntax. Anyways, this is what I have so far:
db = QSqlDatabase.addDatabase("database")
db.setHostName("localhost")
db.setUserName("postgres")
db.setPassword("password")
#Not sure what to do to set the connection. The C++ documentation says to put "bool ok = db.open();"
model = QSqlQueryModel()
model.setQuery("SELECT name, density, deveff FROM public." +str(filename)+ "_rezoning ORDER BY gid;")
model.setHeaderData(0, Qt.Horizontal, "Name")
model.setHeaderData(1, Qt.Horizontal, "Density")
model.setHeaderData(2, Qt.Horizontal, "DevEff")
view = QTableView()
view.setModel(model)
view.show()
What happens when I click the button in my GUI to run the calculations, a small blank QGIS window briefly flashes and goes away. At least I'm not getting an error, but it's obviously not complete. I assume part of the issue is the connection to the database that is missing and that I do not know how to set. The other issue is that I would like this to show in the tableView widget in the GUI, but I'm not sure how to specify this...
Any further tips? I really appreciate it.
Roman
If you're planning to use Qt widgets and models, PySide (PyQt, or plain Qt/C++) is the way to go.
With bare psycopg2 you'll have a lot more work to do, and you'll need to implement your own model in order to leverage Qt's model/view classes. This is simply not the Qt way of doing things. PySide (and PyQt) has it own means to connect to a supported database, there's no need for pure Python database adapters like psycopg2. It uses the underlying libqt4-sql library (C++) and the installed plugins (QPSQL, QMYSQL, QSQLITE, etc).
Essentially you need to:
Connect to a database.
Instantiate a model (QSqlQueryModel, QSqlTableModel or a custom QAbstractTableModel derived class)
Attach that model to a view (ie. QTableView).
Take a look at the PySide QtSql Documentation and the PyQt documentation to get an idea. They're mostly compatible/interchangeable, but at a glance I see that the PyQt documentation looks more complete.
EDIT (after your edit):
A Qt GUI application requires an event loop to run, and that's provided by a QApplication instance. Before going any further with the specifics of your app, take the time to understand a few basic concepts first. Here's a nice Getting Started with PyQt Guide.