I am trying to write a python program that will count the words on a web page. I use Beautiful Soup 4 to scrape the page but I have difficulties accessing nested HTML tags (for example: <p class=”hello”> inside <div>). Every time I try finding such tag using page.findAll() (page is Bea…
Category: Questions
%% Cell magic tag not working in Jupyter notebook?
I’m new to Jupyter notebook and I’m trying to set one up with Python and R, using rpy2. I have the line which gives me the error SyntaxError: invalid syntax However when I use just one %, such as this works fine. How can I fix this issue? I am using Python 2.7. Answer % prefix is for a line
seaborn pointplot and boxplot in one plot but shifted on the x-axis
I want to plot both a boxplot and the mean in one figure. So far my plot looks like this using these lines of code: I would like to shift my mean ‘x’ markers a bit to the right so that the errorbars don’t overlap with the whiskers from the boxplot. Any idea how to do that? A bonus question:
NumPy/PyTorch extract subsets of images
In Numpy, given a stack of large images A of size(N,hl,wl), and coordinates x of size(N) and y of size(N) I want to get smaller images of size (N,16,16) In a for loop it would look like this: But can I do this just with indexing? Bonus question: Will this indexing also work in pytorch? If not how can I
Python – instance attribute defined outside __init__()
I get the warning in question for the following code: How should I fix this? I tried to move everything to init but then I had some errors for passing the arguments in the line I was creating the Autocompelete object. So please provide me with all the changes I have to make. not just smth like you have to
How to count the number of times a specific character appears in a list?
Okay so here is a list: I want to be able to count the total number of times a user inputted letter appears throughout the entire list. Let’s say the letter is ‘a’ I want the program to go through and count the number of times ‘a’ appears in the list. In this case, the total numb…
How to convert JSON data inside a pandas column into new columns
I have this short version of ADSB json data and would like to convert it into dataFrame columns as Icao, Alt, Lat, Long, Spd, Cou….. After Alperen told me to do this I can load it into a DataFrame. However, df.acList is [{‘Id’: 10537990, ‘Rcvr’: 1, ‘HasSig’: False, &#…
Proper use of comments
For Python code, PEP 257 provides a convention for using docstrings to document structural entities: packages, modules, functions, classes, and methods. This covers pretty much everything. Stack Overflow questions about how to comment Python code invariably elicit answers saying to use docstrings. Where does …
Python can’t read the environment variable
I used Ubuntu16.04 When I use sudo python3 into the interactive shell it can’t read the SECRET_KEY I set it in the /etc/profile.d/project.sh project.sh After reloading it but in vain. I also set in the ~/.profile But still got the error. How do I fixed it? [EDIT] It can work in sudo -E python3 But the f…
Get the list of packages installed in Anaconda
Over a period of time, I have loaded a number of packages into the Anaconda I have been using. Now I am not able to keep track of it. How do we get a list of all packages loaded in Anaconda (Windows 10)? What is the command? Answer in terminal, type : conda list to obtain the packages installed using