I have the following dataframe: a b 1 None 1 ‘w’ 2 None 2 ‘z’ And I want to repeat the values that are not None in column ‘b’, but based on the value in column ‘a’. At the end I would have this dataframe: a b 1 ‘w’ 1 ‘w’ 2 ‘z’…
Tag: python-3.x
Second y-axis not showing when using matplotlib
I am trying to plot data_1 and data_2 against data (data supplied in example) using 2 y-axis on different scales. When I run my code it seems only data_2 gets plotted. I am limited to only use the matplotlib library for this. Am I missing something here? Answer They are plotted over each other. Change the lin…
Compare two dataframe column values and join with condition in python?
I need to join the below dataframe based on some condition. df_output I need to join two dataframe df1, df2 based on Id column but every element should be in df.Id list that’s when we consider it a match. Answer While this isn’t a highly efficient solution, you can use some sets to solve this prob…
HTML problem with tags and classes in a simple and little scraping with BeautifulSoup
I am new and am trying to get BeautifulSoup to work. I have Html problems with recovering classes and tags. I get closer, but there is something I’m wrong. I insert wrong tags and classes to scrape the title, time, link, and text of a news item. I would like to scrape all those titles in the vertical li…
Write a program to print the sum of 1 to n. While calculating sum omits the numbers which are multiples of x. Note :Use the concept of continue
Please help me with this I’m not able to omit number of multiple x Answer Keywords such as for and continue shouldn’t be capitalized: If you’re trying to find the sum of numbers that are not multiples of x then you can try this:
Updating a variable inside the for loop is not working
in this below code, I am trying to update rsum value to (rsum – lsum – nums[i]) inside for loop, it’s giving me the wrong output. But if I declare a new variable name and assign (rsum – lsum – nums[i]) value to that, it gives me the right output. What’s the reason behind th…
Class Instantiation, and variable sharing for abstract/static classes
Simple example of my problem: The issue is that all services in this instance will share subscribers, hence my solution was to create a function that returns the abstract service as such: This now works because subscribers are unique to each class inheriting the abstract service. Issues Is this correct for py…
How to add Python Interpreter to PyCharm?
I followed a lot suggestions to add the interpreter to PyCharm, but they’re simply not working. I want to figure out what the exact problem is here. First, it said no interpreter is found, so I tried using Python 3.10 in Anaconda. But it seems “pip install packages” don’t get used for …
How to extract element from two similar tags in one code?
I am trying to extract year from multiple xml files. Initially, the xml files are as follows, I used It had worked well. But in some xml files the tag is changed to TaxPeriodEndDate I tried to revise the code to It did not work. No error message, but no output. Any suggestion is highly appreciated. Thank you.…
ModuleNotFoundError: No module named ‘sharedFunctions’
I have a Python project in which I have the following folder structure: The download_module/__init__.py has the following code: The sharedFunctions.py file contains the following function: Then on the useSharedFunction.py I try to import the shared function and use it like this. When I try to run this by usin…