I have a string (str_json) that I’m getting from elsewhere : This is a string str_json which is supposed to be JSON but it actually contains some python code and a number value and single quotes. json.loads will fail. What I need is the JSON string of str_json. json_data = json.loads(str_json) What I…
Tag: python
PyQT: Storing multidimensional data and displaying as QTableView using model/view framework
EDIT: I’ve changed my approach since asking this question – see answer below. I’m building an application which displays data in a series of tables. I’m currently using PyQT’s item-based QTableWidget and manually updating the tables whenever data changes. I’d like to migrat…
Python count up by 5 after each iteration in for loop
I am trying to open a csv file in python and read the rows into a list. The list is then sent to a function where I want to add 5 to the value of x after each iteration with the value of d going up by 10 after every 10th iteration. d I have working but can’t quite figure
Push data to Campaign Monitor using Python
Campaign Monitor is a service where we can send emails to a set of subscribers. We can create multiple lists within Campaign Monitor and add the required users to these lists as subscribers(to whom we can send personalised emails). So, here I am trying to send a set of customers’ details like their name…
How to create new list of lists using for loop
I have two lists like I want to extract the required elements 1 and 3 from each list contained in values, to create a new list of lists like [[‘1234’, 50], [‘5678’, 100]]. I was able to solve the problem with a list comprehension: But how can I write the equivalent with explicit for lo…
Pandas Dataframe – Sum values for a specific date then divide by the count of that date
I have a pandas dataframe with several dates, and several values for each date, I’m trying to sum the values of each date then divide by the number of records for that same date. Example: date value 2022-09-16 1 2022-09-16 2 2022-09-16 3 2022-09-15 6 2022-09-15 2 2022-09-15 2 2022-09-14 7 The expected r…
fit multiple parametric curves with scipy python
I am trying to fit two curve into one equation. y = (a * exp(b * (T^-1)))cexp(d100)(x^0.5) for y1, T =10, for y2, T =25. how do a get a,b,c,d I have a code that simplified to fit one data. I don’t know how to do both. I find a similar question with solution but I can’t follow.. fit multiple
What’s a good pattern for typehinting with `Literal` and then validating at runtime?
Let’s say I have a class: I would like to maintain the list of viable values, i.e. ‘floor’, ‘ceil’, ‘square’, in only one place. What’s a good recipe for this? The MyPy docs show some ideas with this suggestion of assert_never but that’s just for MyPy to g…
Shipping Charges calculator not producing the correct result
The following is a sample of a running program: This is what I have so far: how would I find the sum of all charges? And how would I be able to have the second question come after the cost? So it would display: Answer I did not quite understand this statement how would I find the sum of all
skip na while removing consecutive same numbers in a column in python
I have to remove the consecutive same number from the column in a dataframe. I am able to remove the number one time, but when I try to do it for the second time the loop does not work as there is one na value in between. dataframe is I dont know why the last line of code i.e. elif