python-3.x

AWS Lambda, Python, Numpy and others as Layers

依然范特西╮ 提交于 2021-02-08 14:57:18
问题 I have been going at this for a while trying to get python, numpy and pytz added to AWS Lambda as Layers rather than having to zip and throw it at AWS with my .py file. I was able to follow multiple tutorials and all of them failed. I have resorted to following this guide if I am to go with pandas, numpy or pytz for any functionality (AWS Lambda with Pandas and NumPy - Ruslan Korniichuk - Medium). So this is good but I do not want to have to recreate a zip each time if things change with my

How to extract dollar amount from pandas DataFrame column

匆匆过客 提交于 2021-02-08 14:49:34
问题 I would to get dollar amounts from more than hundreds rows in a column, and then save the amount in a new column. The dollar amount varies in each row, like $100.01, $1,000.05, 10,000, 100,000 etc. One of the lines looks like this: Approving the settlement claim of Mr. X Y by payment in the amount of $120,000.65 I tried to do something like this, but it's not extracting the dollar amount: df['amount'] = df['description'].str.extract('/(\$[0-9]+(\.[0-9]{2})?)/', expand=True) Please help. 回答1:

creating class properties dynamically

北城余情 提交于 2021-02-08 14:10:56
问题 I am looking for a way to dynamically create classes with specific properties accessible via typical instance notation. DynoOne = createClass('DynoOne',props=['A','B']) d = DynoOne (database='XYZ') d.A = d.B + 1 DynoTwo = createClass('DynoTwo',props=['A','C','E']) q = DynoTwo (database='QRS') q.A = q.C + 2*q.E Details of how the "props" are actually acquired and modified would be hidden. This also makes it easier to add access to new props as they become available. I have experimented with

Pandas how to get rows with consecutive dates and sales more than 1000?

江枫思渺然 提交于 2021-02-08 14:09:13
问题 I have a data frame called df : Date Sales 01/01/2020 812 02/01/2020 981 03/01/2020 923 04/01/2020 1033 05/01/2020 988 ... ... How can I get the first occurrence of 7 consecutive days with sales above 1000? This is what I am doing to find the rows where sales is above 1000: In [221]: df.loc[df["sales"] >= 1000] Out [221]: Date Sales 04/01/2020 1033 08/01/2020 1008 09/01/2020 1091 17/01/2020 1080 18/01/2020 1121 19/01/2020 1098 ... ... 回答1: You can assign a unique identifier per consecutive

Pandas how to get rows with consecutive dates and sales more than 1000?

有些话、适合烂在心里 提交于 2021-02-08 14:04:36
问题 I have a data frame called df : Date Sales 01/01/2020 812 02/01/2020 981 03/01/2020 923 04/01/2020 1033 05/01/2020 988 ... ... How can I get the first occurrence of 7 consecutive days with sales above 1000? This is what I am doing to find the rows where sales is above 1000: In [221]: df.loc[df["sales"] >= 1000] Out [221]: Date Sales 04/01/2020 1033 08/01/2020 1008 09/01/2020 1091 17/01/2020 1080 18/01/2020 1121 19/01/2020 1098 ... ... 回答1: You can assign a unique identifier per consecutive

Recommended way of closing files using pathlib module?

*爱你&永不变心* 提交于 2021-02-08 13:32:07
问题 Historically I have always used the following for reading files in python : with open("file", "r") as f: for line in f: # do thing to line Is this still the recommend approach? Are there any drawbacks to using the following: from pathlib import Path path = Path("file") for line in path.open(): # do thing to line Most of the references I found are using the with keyword for opening files for the convenience of not having to explicitly close the file. Is this applicable for the iterator

How do I write a BeautifulSoup strainer that only parses objects with certain text between the tags?

北城余情 提交于 2021-02-08 13:24:10
问题 I'm using Django and Python 3.7. I want to have more efficient parsing so I was reading about SoupStrainer objects. I created a custom one to help me parse only the elements I need ... def my_custom_strainer(self, elem, attrs): for attr in attrs: print("attr:" + attr + "=" + attrs[attr]) if elem == 'div' and 'class' in attr and attrs['class'] == "score": return True elif elem == "span" and elem.text == re.compile("my text"): return True article_stat_page_strainer = SoupStrainer(self.my_custom

Prevent script dir from being added to sys.path in Python 3

 ̄綄美尐妖づ 提交于 2021-02-08 13:17:33
问题 Is there a way to prevent the script's directory from being added to sys.path in python3? I'm getting import conflicts due to the fact that imports are relative in python. A legacy project I'm working with has a file called logger.py in the root directory of the script which conflicts with the built-in logger . The custom build system that I use ends up creating symlinks to all the files and dependencies and in production, at runtime we use the -E flag to ignore any system set PYTHONPATH and

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 3)

戏子无情 提交于 2021-02-08 13:14:09
问题 I have written code using matmul, but I am getting the following error: "ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 3)" Code: R = [[0.40348195], [0.38658295], [0.82931052]] V = [0.33452744, 0.33823673, 0.32723583] print("Rt_p: ", R) B = np.matmul(V,np.transpose(R))/pow(LA.norm(R), 2) print("B", B) 回答1: You are transposing a Matrix with 3 rows and 1 column to a Matrix with 3 columns and 1

ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 3)

只谈情不闲聊 提交于 2021-02-08 13:13:58
问题 I have written code using matmul, but I am getting the following error: "ValueError: matmul: Input operand 1 has a mismatch in its core dimension 0, with gufunc signature (n?,k),(k,m?)->(n?,m?) (size 1 is different from 3)" Code: R = [[0.40348195], [0.38658295], [0.82931052]] V = [0.33452744, 0.33823673, 0.32723583] print("Rt_p: ", R) B = np.matmul(V,np.transpose(R))/pow(LA.norm(R), 2) print("B", B) 回答1: You are transposing a Matrix with 3 rows and 1 column to a Matrix with 3 columns and 1