python-3.6

Error with compiled Pillow on Python 3.6 virtualenv

半世苍凉 提交于 2019-12-11 16:09:05
问题 I am running a linux box with ubuntu 14, it runs an apache2 server that hosts a Django application. This application imports PIL from the installed Pillow library. It was all working fine when I was on Python 3.5, however after upgrading to Python 3.6 and reinstalling Pillow in the Virtualenv, I get an error when the webserver tries importing PIL. When I run the Python interpreter it all imports fine as it uses the py script directly however as the webserver is using the installed and

UnicodeEncodeError with Visual Studio Post-Build Command Line

六眼飞鱼酱① 提交于 2019-12-11 16:06:30
问题 I am trying to run a Python script from a Visual Studio C/C++ project's Post-Build Command Line. The arguments for the script contain German Umlauts, let's say Ü . The Command Line Script is python "<path to python .py>" Ü The Python script simply prints the first (second) argument back to the Command Line: import sys if __name__ == "__main__": print(sys.argv[1]) However, this raises an exception for the last line: ... File "C:\Python36\lib\encoding\cp1252.py", line 19, in encode return

How to filter dataframe based on ip range

橙三吉。 提交于 2019-12-11 15:17:41
问题 I have dataframe which has 2 columns. I want to filter this dataframe based on ip ranges present in json file. ip_ranges.json [ {"start": "45.43.144.0", "end": "45.43.161.255"} {"start": "104.222.130.0", "end": "104.222.191.255"} ... ] Dataframe: ip,p_value 97.98.173.96,3.7 73.83.192.21,6.9 ... Note: ip_range.json contains 100k elements and my dataframe has 300k rows. Currently, I implemented like this Created python list to store all ips in each range. For example ["45.43.144.0", "45.43.144

Search patterns from the text file and if pattern missing place a value Null

吃可爱长大的小学妹 提交于 2019-12-11 15:17:34
问题 Esteemed colleagues, I have a raw data format as i detailed below where primarily it has to be three line and every line is starts with pattern dn: following ftpuser and description , whereas there are situations where the third line description is missing hence First two lines are intacted in this case. Now, I'm using a multiline regex to match all these patterns and using it to get the data from my data variable and this is passed to the regex(re.findall), Further, i have for looped the

Django 2 email unsubscribe link

一曲冷凌霜 提交于 2019-12-11 15:14:21
问题 I want to add an unsubscribe link in emails being sent to the user. I am unsure on how to achieve it. I want the user to be able to unsubscribe without having to log in. Any suggestions on how to achieve this would be appreciated. Thanks 回答1: I'll assume you know how to send an email with django, and other basic things. For every email you send to them, you have to build the unsubscribe link first, like the following. Note that the following has a url pattern, and a model that takes a uuid

Display different numbers of decimals in an f-string depending on number's magnitude?

风格不统一 提交于 2019-12-11 14:48:45
问题 The goal is to use an f-string to round a float to a different number of decimal places based on the size of the number. Is there in-line f-string formatting that works like the following function? def number_format(x: float): if abs(x) < 10: return f"{x:,.2f}" # thousands seperator for consistency if abs(x) < 100: return f"{x:,.1f}" return f"{x:,.0f}" # this is the only one that actually needs the thousands seperator 回答1: Although it is not something that can go in-line in an f-string, the

why the following Bigquery insertion is failing?

烈酒焚心 提交于 2019-12-11 14:26:01
问题 Hello I am trying to insert one row into a table, I succesfully created the table as follows: schema = [{'name': 'foo', 'type': 'STRING', 'mode': 'nullable'},{'name': 'bar', 'type': 'FLOAT', 'mode': 'nullable'}] created = client.create_table(dataset='api_data_set_course_33', table='insert_test_333', schema=schema) print('Creation Result ',created) However when I push the row I got False, rows = [{'id': 'NzAzYmRiY', 'one': 'uno', 'two': 'dos'}] inserted = client.push_rows('api_data_set_course

Best way(run-time) to aggregate (calculate ratio of) sum to total count based on group by

若如初见. 提交于 2019-12-11 12:57:20
问题 I'm trying to identify ratio of approved applications(identified by flag '1' and if not then '0') to total applications for each person(Cust_ID). I have achieved this logic by the following code but it takes about 10 mins to compute this for 1.6 M records. Is there a faster to perform the same operation? # Finding ratio of approved out of total applications df_approved_ratio = df.groupby('Cust_ID').apply(lambda x:x['STATUS_Approved'].sum()/len(x)) 回答1: I think need aggregate by mean : df = pd

Python 3.6: Deal with MemoryError

独自空忆成欢 提交于 2019-12-11 08:13:58
问题 There is a software I have written for 'machine learning' mission. To do this, I need to load a lot of data into the RAM of the program (for the required 'fit' function). In practice, in the spoken run, the 'load_Data' function should return 2 'ndarrays' (from 'numpy' library) of approximately 12,000 to 110,000 size of float64 type. I get Memory Error during the run. I tested the program on a smaller dataset (2,000 by 110,000 array) and it does work properly. There are 2 solutions I have

Attribute Error while using cx_Freeze

≯℡__Kan透↙ 提交于 2019-12-11 07:07:38
问题 while creating exe of my python game . I got the following error my code in setup.py is import cx_Freeze import os os.environ['TCL_LIBRARY'] = "C:\\Users\Vinayak Singla\\Appdata\\Local\\Programs\\Python\\Python36-32\\tcl\\tcl8.6" os.environ['TK_LIBRARY'] = "C:\\Users\Vinayak Singla\\Appdata\\Local\\Programs\\Python\\Python36-32\\tcl\\tk8.6" executables = [cx_Freeze.Executable("pong.py")] cx_Freeze.setup( name="Pongy", options={"build_exe": {"packages":["pygame","sys","random","time"],"include