Skip to content

Efficient regex with lists

I have a list of strings coming from os.listdir() that looks like the following: out of those entries, I wanna get the ones that match the “backup_YYYYMMDD” pattern. The regex for that, with named groups, would be I am trying to create a list that contains the date only from the above (aka the .gr…

How to get the path of a function in Python?

I want to obtain the file path of a function in Python. How to do it? For example, Thank you. Answer You can use the getfile() function from the inspect module for this purpose. For example, given the following files: inspect-example.py external_def.py Executing inspect_example.py produces the following outpu…

Error column doesn’t exist on custom module Odoo

I’m working on a custom module and i need to add field to res.partner model. I’ve add some field to this model but since 1 week, when i try to add a new one i got this error : Other field works good but not this one : I really don’t unterstand why i have this issue. I’ve try to

Pycharm Can’t install TensorFlow

I cannot install tensorflow in pycharm on windows 10, though I have tried many different things: went to settings > project interpreter and tried clicking the green plus button to install it, gave me the error: non-zero exit code (1) and told me to try installing via pip in the command line, which was succ…

Pyspark: how to duplicate a row n time in dataframe?

I’ve got a dataframe like this and I want to duplicate the row n times if the column n is bigger than one: And transform like this: I think I should use explode, but I don’t understand how it works… Thanks Answer The explode function returns a new row for each element in the given array or m…

Reverse a get_dummies encoding in pandas

Column names are: ID,1,2,3,4,5,6,7,8,9. The col values are either 0 or 1 My dataframe looks like this: I want the column names in front of the ID where the value in a row is 1. The Dataframe i want should look like this: Please help me in this, Thanks in advance Answer set_index + stack, stack will dropna by …