Using pandas read_csv with missing data

I am attempting to read a csv file where some rows may be missing chunks of data. This seems to be causing a problem with the pandas read_csv function when you specify the dtype. The problem appears that in order to convert from the str to whatever t

Python: The default entry function that represents everything

Is there a variable in python that stands for everything? I have a function called filter: def filter(df, col1 = ?, col2 = ?, col3 = ?): return df.loc[(df.col1 == col1) & (df.col2 == col2) & (df.col3 = col3),:] What should ? be? ==================

How to sort by job title in Python

I have a class called Shareholder and each Shareholder can have one of 4 job titles: president, vice_president, secretary, or treasurer (in that order). I would like to sort a list of shareholders by their job title, but I don't know how to do this o

Python Flask Render Text from Variable like render_template

I know the flask function render_template. I have to give the file name of the template. But now I want to render the string of a template (that is the content of the template). That makes sense. but I don't want to explain now why. How can I render

Save a generated image with a wand to django ImageField

I'm trying to generate a preview for an "overlay" config stored in a django model than will be applied later to other model. I have not much experience manipulating files with python... =( Here is my code: import io from django.conf import setti

Python Subprocess Timeout

def adbshell(command, serial=None, adbpath='adb'): args = [adbpath] if serial is not None: args.extend(['-s', serial]) args.extend(['shell', command]) return subprocess.check_output(args) def pmpath(serial=None, adbpath='adb'): return adbshell('am in

Variable size problem with Python

I got the following scenarios: 1) car on the right shoulder 2) car on the left shoulder 3) car on the shoulder I want to match "shoulder" when left|right is not present. So only 3) return "shoulder" re.compile(r'(?<!right|right\s*)s

Cron runs a sh script that executes a python script

I have a cronjob that executes a sh script. The script also executes the following python script: #!/usr/bin/python print "Running python script" LANG = "en_US.UTF-8" import sys py3 = sys.version_info[0] > 2 u = __import__('urllib.r

Python: Is not it the same as & ldquo; & rdquo;?

I'm relatively new to Python and Coding. I've been doing fine until I've come across "None": variable = None while variable != "": print("Why does this loop start?") While it seems simple I can't grasp why the above loop begi

python & ldquo; class & ldquo; word problem

The question reads Write a class named Car that has the following data attributes: __year_model( for the car's year model) __make(for the car's make of the car) __speed( for the car's current speed) The Car class should have a __init__ method that ac

Troubleshooting Python if statement

Python Version : 2.7 Just wondering what is wrong with the following code : def bmi_cat(bmi): if bmi < 18.5: return "underweight" elif (bmi >=18.5 or bmi < 25): return "normal" elif (bmi >=25 or bmi < 30): return "o

flask-mail gmail: connection refused

I'm getting the following error when I attempt to use flask-mail to send an email through my gmail account. error: [Errno 10061] No connection could be made because the target machine actively refused it I've tried configuring flask-mail in various w

How do I transfer an operator to a python function?

I'd like to pass a math operator, along with the numeric values to compare, to a function. Here is my broken code: def get_truth(inp,relate,cut): if inp print(relate) cut: return True else: return False and call it with get_truth(1.0,'>',0.0) which s

Conversion of color space with cv2

I'm migrating from cv to cv2 and I'm having difficulties finding an equivalent of the cv.CvtColor function. I read in the documentation that cv2.cvtColor existed but I don't know how to use the third parameter. cv2.CV_BGR2Lab doesn't exist. Neither d

Print the character when copying the large folder

I have this function trying to print additional '.' every second while it's copying a big folder (~3GB) from one place to another: def copy_folder(source, destination): print 'copying', while shutil.copytree(src=source, dst=destination): print '.', t

Unmake move vs copy board in chess programming

I'm at the start of creating a chess engine. When I created a function that checks if a move is legal, first I had to make the move and then check if the move had put my king in check and then unmake it. After giving some thought on how to make a fun

Find specific variables in a function and return them sorted

first of all, thank you for your help in forward. I'm using Python and I'm trying to search a .py file for all of its functions starting with the name "test_" and all of the variables included. The variables I search for are formatted like this:

Inserts do not appear to occur

I'm using gevent with gevent-mysql (I also used pymysql to the same effect). It does selects just fine but no matter what I do I can't get it to run an insert. I'm out of ideas. conn = geventmysql.connect(host='localhost', port=3306, user='root', db=

What is the best interface from Python 3.1.1 to R?

I am using Python 3.1.1 on Mac OS X 10.6.2 and need an interface to R. When browsing the internet I found out about RPy. Is this the right choice? Currently, a program in Python computes a distance matrix and, stores it in a file. I invoke R separate

Displaying a Matrix with Complex Numbers (CV_64FC2)

I'm new to OpenCV, and I would like to compare the results of a python program with my calculations in OpenCV. My matrix contains complex numbers since its the result of a cvDFT. Python handles complex numbers well and displays it with scientific not

What is the PyObjC code for Objective-C?

Possible Duplicate: Calling Python from Objective-C I'm a long-time Python programmer and short-time Cocoa programmer. I'm just getting started with PyObjC and it's really amazing how easy it it is to get stuff done. That said, I wanted to try using