I have multiple data frames in my analysis. For example dataframe 1 where this is the number of people by activity in China Activity No of people Activity 1 100 Activity 2 200 Activity 3 300 and data frame 2 where this is the number of people by acti
I have this dataframe: source target weight 24517 class social 31 24356 class proletariat 29 16189 bourgeoisi class 29 24519 class societi 29 24710 class work 28 15375 bourgeoisi class 26 23724 class condit 24 24314 class polit 24 ... How can I creat
I am new to Python, can anyone please point out the mistake, i have made in the code: numlist = [3,2,5,5,7,6,1,8,4] def peaks(numlist): exceed = [] for elem in numlist: for num in exceed: if elem not in exceed: if num in exceed < elem in numlist: exc
Something is wrong in my script and I found the error, but I'm completely stuck. there is array b which contains two elements: b = np.zeros ((1,2)) b[0,0] = 272 b[0,1] = 1578 I want to check if there are elements in the second columns, greater than a
I'm still very new to coding, as in I've been coding for a few days. I'm trying to teach myself python by working on a small personal project. I've been playing around with list slicing, and something doesn't add up to me, which is impeding a functio
Ok, I'm sure there is a very easy way to do this, but I'm rusty in python and I can't work out the pythonic way to do this. I have a list, representing the hours of the day: import numpy as np hourOfDay = np.mod(range(0, 100), 24) Then I want to crea
suppose I have the module myscript.py; This module is production code, and is called often as %dir%>python myscript.py foo bar. I want to extend it to take keyword arguments. I know that I can take these arguments using the script below, but unfortun
This question already has an answer here: How do you remove duplicates from a list in whilst preserving order? 33 answers I have a problem in my code where I have the following: import random Probabilities={'AA':0.2,"TT":0.2, "GG":0.1,
I'm getting the error "The role defined for the function cannot be assumed by Lambda" when I'm trying to create a lambda function with create-function command. aws lambda create-function --region us-west-2 --function-name HelloPython --zip-file
I am very new to Python, trying to learn the basics. Have a doubt about the list. Have a list: L = [[1,2,3],[4,5,6],[3,4,6]] The output should be: [[2,4,6],[8,10,12],[6,8,12]] The code that works for me is the following for x in range(len(L)): for y
I'm having trouble writing a regular expression that would find and remove suffixes in names in strings. I had it working fine just looking for the suffix (e.g. 'III', 'IV'), until I had names with IV start appearing. I know the logic once I get the
I am running a search on a list of ads (adscrape). Each ad is a dict within adscrape (e.g. ad below). It searches through a list of IDs (database_ids) which could be between 200,000 - 1,000,000 items long. I want to find any ads in adscrape that don'
I did the following tutorial to connect my Raspberry Pi with an application on Bluemix using the IoT Foundation: https://developer.ibm.com/bluemix/2015/04/02/tutorial-using-a-raspberry-pi-python-iot-twilio-bluemix/ I have the following problem: If I
My system is composed of a python application that is launched from supervisord. Let's call it A. A launches a subprocess B to do some of its task. Both A and B are coded in Python and use the standard logging module to output messages to the console
I am trying to use Google Drive API (Python) to download some tabs of a spreadsheets file. Are the gids information in the file's metadata? What I am trying to do is (this may not be correct, please suggest :)) : file_metadata = self.service.files().
I have a package called analysis. When I import this package (with the command from app import analysis) I get an ImportError exception because of a missing library that should be imported in another package (web_package). I want to be able to import
I want to create a new file for each iteration, but I'm not able to do so. I'm only able to update the same old file, how could I solve this? The other more basic question what is "" function in file.write("".)? I have tried with "
link = models.URLField(max_length=500, blank=True, default='') I have already set the max_length as 500, but every time I tried to set this field with url larger than 200 characters, it still threw an error saying that Ensure this value has at most 2
I want to run a code that need to stanford postagger.jar. but i have this error: File "/usr/lib/python2.7/site-packages/nltk/internals.py", line 562, in find_jar (name, path_to_jar)) ValueError: Could not find stanford-postagger.jar jar file at
I am making a robot that will have a webcam on it to provide some simple object detection. For right now, I would like to simply stream the video to a webpage hosted on the robot and be able to view it from another device. I have written a simple tes
This question already has an answer here: Why do I need 'b' to encode a Python string with Base64? 5 answers I'm trying to encode an int in to base64, i'm doing that: foo = 1 base64.b64encode(bytes(foo)) expected output: 'MQ==' given output: b'AA=='
Here is a section (a large section) of my code. http://pastebin.com/KCZNkYNB What i have happening, by design, is to iterate through this sequence until the distance that i am calculating is minimized by 1cm. I don't want to move on to my next epoch
I am in a class teaching python and am a beginner at any sort of coding. I keep running into this problem and I can't find anything in my text book or additional handouts explaining what I'm doing wrong. Here is an example taken from one of the exerc
Suppose, I have a modifying statement: cursor = conn.cursor() # some code affected_rows1 = cursor.execute(update_statement1, params1) # some code conn.commit() cursor.close() Should I wrap the block of code with a try ... except and explicitly rollba
I have a quick one off task in a python script that I'd like to call from Django (www user), that's going to need to root privileges. At first I thought I would could use Python's os.seteuid() and set the setuid bit on the script, but then I realized
Situation Similar to this question, I'm looking for a way to create a GUI where users are able to see a graph (in the graph theory sense) and interact with it. Vehicles will move across the graph from none to node over time. Users should be able to a
In Python, what is the difference between add and __add__ methods?A method called add is just that - a method with that name. It has no special meaning whatsoever to the language or the interpreter. The only other thing that could be said about it is
How can I do a for() or foreach() loop in Python and Perl, respectively, that only prints every third index? I need to move every third index to a new array.Python print list[::3] # print it newlist = list[::3] # copy it Perl for ($i = 0; $i < @list;
Are there better alternatives to PIL (Python Imaging Library) for basic image file I/O and processing in Python?Try Pillow: http://pypi.python.org/pypi/Pillow It's a fork of PIL but maintained by Plone community. Which is great as it is being maintai
I'm writing a url rewrite in django that when a person goes to http://mysite.com/urlchecker/http://www.google.com it sends the url: http://ww.google.com to a view as a string variable. I tried doing: (r'^urlchecker/(?P<url>\w+)/$', 'mysite.main.view