Pandas find max stable interval

I implemented some script using pandas, but I´m not sure if it is the most elegant/fast implementation. (I'm using a for loop...) Suppose you have a y variable (float) vs time What I need to do is create a new column (0 or 1) on the dataframe indi...
more »

2017-04-18 23:04 (2) Answers

python: cv2.threshold changes numpy to tuple

I process every frame in first function where i am usingcv2.threshold(self.res, 10, 255, cv2.THRESH_BINARY_INV) for preprocessing before detecting motion. In next function I am just counting number of black pixels and calculating average. I am giving...
more »

2017-04-18 23:04 (0) Answers

How to modify full text of some columns in pandas

I got a fairly big dataframe from a csv in pandas. The problem is that on some columns I get strings of text which I would like to isolate the last character to turn it into integers. I found a solution, but I am fairly sure it's not the most effic...
more »

2017-04-18 23:04 (2) Answers

Polymorphism and Classes in Python

I am having trouble completing this assignment for school. This picture is what the output should be when complete. Here is the problem I am tasked with: "In the file creates four objects. (vehicle, sedan, truck, hatchback) The shou...
more »

2017-04-18 22:04 (3) Answers

Python Pandas, apply function

I am trying to use apply to avoid an iterrows() iterator in a function: However that pandas method is poorly documented and I can't find example on how to use it, except for the lame .apply(sq.rt) in the documentation... No example on how to use arg...
more »

2017-04-18 21:04 (4) Answers

Python: compare and sort tuples in list

I'm trying to sort a list of points (their IDs). The tuples are a result of a minimum spanning tree (using networkx) of a graph in which every node is connected to every other node, but their weights differ. I need to extract a (shortest) path for ea...
more »

2017-04-18 19:04 (1) Answers

Function doesn't return right values

I am stuck on this problem for hours now. I have written a Python code to read and convert data from a text file and everything is running fine. simulink_robot_motor1=[] with open('C:\\Users\...\sensor_data.txt',"r") as data_file: rows=0 fo...
more »

2017-04-18 18:04 (2) Answers

Fbprophet quickstart example - KeyError: 'ds'

Following the quickstart example & having a problem when trying to fit the model at:; The terminal shows: Traceback (most recent call last): File "/home/cartier/miniconda2/envs/prophet/lib/python3.6/site-packages/pandas/indexes/base...
more »

2017-04-18 18:04 (1) Answers

Comparison by category in Pandas

I have a dataframe roughly like this: category value 1 A 2 2 B 5 3 A 3 4 A 2 5 B 1 Now I want to add a column that tells me if the current value is above or below the medium in i...
more »

2017-04-18 16:04 (1) Answers

How to store and load huge images dataset?

I have a large image dataset to store. I have 300,000 images. Each image is a vector of 28800 pixels, which means that I have a matrix of (300000, 28800) I stored that as follow img_arr = np.stack(images, axis=0) np.savetxt('pixels_dataset_large.c...
more »

2017-04-18 15:04 (1) Answers

Python Pandas reordering table

I have a dataframe in pandas that looks like this: ID TIME A B C 1 ddmmyy value_of_A1 value_of_B1 value_of_C1 2 ddmmyy value_of_A2 value_of_B2 value_of_C2 3 ddmmyy value_of_A3 value_of_B...
more »

2017-04-18 15:04 (2) Answers

python uses system cpu time when consuming memory

I noticed that when python (may be just numpy?) are taking up memory, system cpu time become significant. For example, when running the following code (numpy multithreading is disabled): import numpy as np a = np.random.rand(50, 50, 1000000) Abou...
more »

2017-04-18 14:04 (0) Answers

Delete route not being hit in my code

images.html <body> {% if msg %} <h1>{{ msg }}!</h1> {% endif %} <div class="container"> <h1>Here you can upload a file</h1> <form id="upload_form" action="/upload" method="POST" enctype="multipart/fo...
more »

2017-04-18 09:04 (0) Answers

input check functions in python classes

I want to create a check on inputs of a particular class, I have the following made up example: class NmbPair: def __init__(self, a = None, b = None): self.a = a self.b = b def __eq__(self, other): if self.a == other...
more »

2017-04-18 09:04 (1) Answers