python-3.7

Why won't subprocess.run take a list of arguments?

Why won't subprocess.run take a list of arguments? Question: I am running a script called mini_medsmaker.py, and in that script I am using subprocess.run to call another script called mini_mocks.py. I am using argparse to list my arguments, and this is the command I am running: subprocess.run(["python", "/path/to/mini_mocks.py", *vars(args).values()]) Whenever I run it, I get …

Total answers: 1

How to change all the values in a nested dictionary in python?

How to change all the values in a nested dictionary in python? Question: I have sample data that looks like this (nested and is dynamic so it does change on the fly): … "counts":{ "1":{ "1":21082, "2":14999 }, "2":{ "1":9180, "2":10023 } }, … I need to recursively go through and replace all the values …

Total answers: 2

Python – alternatives for internal memory

Python – alternatives for internal memory Question: I’m coding a program that requires high memory usage. I use python 3.7.10. During the program I create about 3GB of python objects, modifying them. Some objects I create contain pointer to other objects. Also, sometimes I need to deepcopy one object to create another. My problem is …

Total answers: 3

Printing aligned nested dictionary with keys as rows

Printing aligned nested dictionary with keys as rows Question: Preface: I do not have pandas, or itertools and have very limited modules in this environment so I need to keep this as pythonic as possible. Im using 3.7.3 on Buster debian. I have a nested dictionary called all_dicts that has: All keys will appear in …

Total answers: 2

Save opencv FlannBasedMatcher from python

Save opencv FlannBasedMatcher from python Question: I am trying to save a FlannBasedMatcher created and train with opencv-python 4.5.5.62. The save function of the class only save the parameters. I can also access to the trainDescriptors, but what I would like is to save the flann once trained. Be able to reload it from another …

Total answers: 1

No module named django-admin C:Program FilesPython39python3.exe

No module named django-admin C:Program FilesPython39python3.exe Question: I have 2 python installed in my windows10. 1 – python 3.7.x 2 – python 3.9.x I have these 2 versions because I simultaneously work on different Django versions on my laptop. NOTE: I have renamed python.exe to python3.exe for the version of 3.9.x and kept python.exe for …

Total answers: 1

AttributeError: Can't pickle local object '<locals>.<lambda>'

AttributeError: Can't pickle local object '<locals>.<lambda>' Question: I am trying to pickle a nested dictionary which is created using: collections.defaultdict(lambda: collections.defaultdict(int)) My simplified code goes like this: class A: def funA(self): #create a dictionary and fill with values dictionary = collections.defaultdict(lambda: collections.defaultdict(int)) … #then pickle to save it pickle.dump(dictionary, f) However it gives error: AttributeError: …

Total answers: 2

Replace column name by Index

Replace column name by Index Question: I have the below data in a Dataframe. +—-+——+—-+——+ | Id | Name | Id | Name | +—-+——+—-+——+ | 1 | A | 1 | C | | 2 | B | 2 | B | +—-+——+—-+——+ Though the column names are repeating, ideally, its a comparison of …

Total answers: 1

'DataFrameGroupBy' object has no attribute 'set_index'

'DataFrameGroupBy' object has no attribute 'set_index' Question: I have a dataFrame data. After grouping and resetting the index, I am not able to set my Date column as Index. data = data.groupby(‘Payment Date ‘) data[‘Payment Amount ‘].sum().reset_index() data = data.set_index(‘Payment Date ‘, inplace = True) data.index Error: AttributeError Traceback (most recent call last) <ipython-input-12-581b0b0bf83f> in …

Total answers: 1