Skip to content

Tag: python

Python mocking table schema

I have a simple python function that needs tested that looks like this: However, to test this, I don’t want to test with a real table – I would like to create a Mock schema within my test (and a mock client too). My test currently looks like this: However, when I print returned_schema, I get the f…

Summation of a product of a function and a vector in Sympy

I want to use the following expression in sympy. For example I tried this sympy code, but an error has occurred. How can I manage this? (How to use Symbol’s value as an index of Matrix?) Answer You can use symbolic indices with a matrix but you need to use double indices:

How to disable python rounding?

I’m looking for a way to disable this: print(0+1e-20) returns 1e-20, but print(1+1e-20) returns 1.0 I want it to return something like 1+1e-20. I need it because of this problem: returns f1 is the original function, f2 is f1 shifted by 1 to the left and f3 is f2 moved back by 1 to the right. By this log…

Using Pandas df.loc

I have a DataFrame of a csv file which is being read by pandas. What I am attempting to do is use df.loc to add a new column but only insert values into the column when values from another column, called “SKU” end with “-RF” and “-NEW”. The code I was working on is below. I…

Substitute numbers in a list of type object pandas

I have a dataframe df looking as follows: What I would like to do is to substitute into df[‘cited_ids’] 0 whenever the corresponding id has d=0 (i) and replace d=1 if there is at least one 0 in the list of df[‘cited_ids’] and the previous d was not 0 (ii). In other words, the first ste…

Pandas take number out string

In my data, I have this column “price_range”. Dummy dataset: I am using pandas. What is the most efficient way to get the upper and lower bound of the price range in seperate columns? Answer Alternatively, you can parse the string accordingly (if you want to limits for each row, rather than the to…