EME 210
Data Analytics for Energy Systems

Getting Help

PrintPrint

Getting Help

Overview

There are many sources, outside of this course, from which you can get help when learning Python. It is important to know how to independently get help on Python code from outside sources because these will always be available to you as you develop code in the future, beyond this course. Here, we will cover a few good options:

  1. Google!
  2. Stack Overflow
  3. The help function in Python
  4. The library documentation

1. Google

With the appropriate search text, usually Google will return helpful information in the top three hits. You can search how to do something (e.g., "how to read a csv in Python"), and typically many tutorials will show up. Alternatively, if you get an error message in Python, you can try copying and pasting the message (or the key part of the message) in Google to see if anyone else has encountered this error (often someone has) and how they solved it.

screenshot as described in preceding text
Screenshot of a Google search on how to read a CSV in Python
Downloaded on 2/14/2023

2. Stack Overflow

Stack Overflow provides forums and discussions for anything related to coding (not just in Python). You can search for instructions or error diagnoses, and if you can't find what you are looking for, you can post your own question that others in the community can help you with. It is bad practice to post a question that has already been answered, so don't be surprised if you get rude responses if you do this!

screenshot as described in preceding text
Screenshot of Stack Overflow website
Downloaded on 2/14/2023

3. The help function in Python

In a Code Cell, typing and executing: help(function_name), will return some pared-down documentation of the function, including what the function does and what arguments/parameters it takes (along with default values, if any). Interpreting this sort of help is also discussed in the last part of the previous section, 6.) The basics of functions in Python.

screenshot as described in preceding text
Screenshot of the help function in Python 
Downloaded on 2.14.2023

4. The library documentation

You can also get detailed information on functions, constants, types, and other elements through online documentation. Any features that are natively built-in to Python are described in the Python Standard Library documentation. Functions contained in imported libraries are described in that library's documentation (for example, Pandas). In Python, a "library" is a collection of code, including functions, classes, and variables, among other things.


De-Bugging Code

The following video demonstrates each of these four approaches to getting help with Python:

Debugging Code
Click here for a transcript of Debugging Code.

Hello. In this video, I'm going to briefly chat about some ways that you can debug your code, and how to really solve problems when you encounter them. Because a lot about learning to code is really about learning to understand errors and be able to figure out how to solve those errors to ultimately solve whatever problem you're trying to. And so, today we'll just talk about some of those, some tips in order to help you get started in that process.

Alright, so here we are in a very short code. And there are four ways that we can work on debugging our code. The first is just to Google, for example, you can type how to read_csv into Google, as I've done here. And you can get all of these different answers of people that have written tutorials to documentation, and occasionally even stuff on Stack Overflow. So, this is really the first stop when you're coming up to issues and you're trying to debug your code.

The next step is to use Stack Overflow. A lot of times Stack Overflow will come up in part of your Google search, but you can also use this link here to get to specific python problems. And then you can sort of say read_csv. Let them know that you are not a robot, and you get all of these answers of people that have asked the same question as you and have gotten community-based answers from people that are, you know, experts in Python. So that's, you know, step two.

Something you can do within Python is use the actual help function. And so, here you can just type help, and you can give it whatever command you're struggling with. So, this is a little different from Googling, where you sort of ask a question. This you need to know what the command you're trying to use is. But if you're, you know, you need to use pandas dot read_csv, and something's not going right, and you're not sure what the problem is, you can use the help function. First, you need to make sure your library is installed. And it will actually print out the very intensive documentation about this particular function here to read_csv. And it tells you how to actually do this. It tells you that your file path needs to be a string, or a path object, or path. If you're scrolling through here, you can see here we've got skip rows that we used in our import videos. and it tells you how to use skip rows and lots of other arguments that you may or may not need to use, but that's always an option to use the help function.

And then the last bit of debugging options is to use the actual documentation by the library. Most python libraries, especially those used in this class, will have a large amount of documentation available. Here I have the pandas documentation open, which I just reached by Googling pandas documentation. And they've got a really nice website here with tutorials and everything, but you can click into their user guide, and you can see all of these different options. And they even have a search feature. So again, you can search read_csv, and it'll come up with the documentation that we just saw using the help function. And so, we have these four options for you whenever you are stuck and trying to solve the problem, but you can also always email instructors if you're having a really tough issue.

Credit: © Penn State is licensed under CC BY-NC-SA 4.0