« first day (848 days earlier)      last day (1340 days later) » 

12:12 AM
0
Q: Display a simulation 2D elastic balls using Tkinter

cromodI wrote a module to simulate physics of 2D elastic balls and the community helped me to improve it on this post. Now I implemented a GUI using Tkinter to display the simulation in a window. I'm a beginner in programming GUI and I don't know if my script can be more efficient and/or simpler. M...

 
 
2 hours later…
2:12 AM
0
Q: Is it possible for pandas use read_csv for several files

FelixIs it possible to use pandas read_csv function to read simultaneously several files each one into separate dataframe?

 
 
3 hours later…
5:19 AM
0
Q: Pandas - Error in comparing a float64 column in df to an integer

Square9627I have a column lastseasontype object (no NULL or NaN) in the df draft. I would like to create a new column Age_retired based on the comparison of the last 2 digits of lastseason to 50. Here is the last season column 0 1993-94 1 1990-91 2 1993-94 3 1997-98 Name: lastseas...

 
5:31 AM
0
Q: Plot a pandas dataframe using the dataframe index for x coordinate in bokeh

KrastanovI want to prepare a bokeh plot that uses a ColumnDataSource. The pandas DataFrame that is the source of the data has one column and a datetime index: How do I specify that the x value should be the index. I tried just omitting it, hoping that would be the default, but it did not work: There...

 
 
2 hours later…
7:44 AM
0
Q: Python import csv short code (pandas?) delimited with ';' and ',' in entires

Alexei MartianovI need to import csv in python on Windows. My file is delimited by ';' and have strings with non-English symbols and commas (','). I've read posts: Importing a CSV file into a sqlite3 database table using Python Python import csv to list When I run: with open('d:/trade/test.csv', 'r') as f1...

0
Q: How to get the last element of a level in a multiindex?

parchmentI have a dataframe in this format: a b x 1 1 31 1 2 1 1 3 42 1 4 423 1 5 42 1 6 3 1 7 44 1 8 65437 1 9 73 2 1 5656 2 2 7 2 3 5 2 4 5 2 5 34 a and b are indexes, x is the value. I want to get rows 1 9 73 and 2 5 34, in other words, th...

 
8:21 AM
0
Q: Create mask by coordinates of convex polygons

Katrina MalakhovaI need to draw a 2D binary mask based on array of vertexes of N convex polygons. import numpy as np mask = np.zeros((100, 100), dtype=np.int8) polys = np.array([[[30,32], [36,46], [41,48], [50, 36]], [[10,32], [16,46], [30,48], [40, 36]], [[56,44], [58,70], ...

 
9:21 AM
-1
Q: Python Looping Through 2 Lists

W CecilI have two lists list1 has 205 values in it list2 has 42025 values in it I would like to print to a csv or txt file the first value in list1 with the first 205 values of list 2 and so on. Example output: List1 value1, list2 value1 List1 value1, list2 value2 List1 value1, list2 value3 I'v...

 
9:34 AM
0
Q: Save numpy array as binary to read from FORTRAN

PUJAI have a series of numpy array, i need to save these numpy array in a loop as a raw binary float32 (without any header information) which need to be read from FORTRAN. import numpy as np f=open('test.bin','wb+') for i in range(0,10): np_data=np.random.rand(10,5) fortran_data=np.asfortran...

 
9:54 AM
14
Q: How can I perform two-dimensional interpolation using scipy?

Andras Deak This Q&A is intended as a canonical(-ish) concerning two-dimensional (and multi-dimensional) interpolation using scipy. There are often questions concerning the basic syntax of various multidimensional interpolation methods, I hope to set these straight too. I have a set of scattered two-dim...

 
10:23 AM
0
Q: Store mouse click event coordinate with matplotlib and perform an operation

DimKoimFollowing the example as given here I try to store the mouse click event and perform an operation. from __future__ import print_function import sys import matplotlib.pyplot as plt import numpy as np def on_move(event): # get the x and y pixel coords x, y = event.x, event.y if event.in...

0
Q: Applying pandas qcut bins to new data

GRNI am using pandas qcut to split some data into 20 bins as part of data prep for training of a binary classification model like so: data['VAR_BIN'] = pd.qcut(cc_data[var], 20, labels=False) My question is, how can I apply the same binning logic derived from the qcut statement above to a new set ...

0
Q: How to multiply rows in matrices in PYTHON?

Eli BorodachMy question is very intuitive in arrays but not in matrices. How can I multiple one element from row of one matrix in all equivalent row in other matrix. Let's assume I have: x = np.matrix([[1], [2]]) y = np.matrix([[3, 4], [5, 6]]) and I want to get as a result: [[3, 4], [10, 12] or in a...

 
11:02 AM
0
Q: install pandsql on OSX

Rahn $ sudo pip install -U pandasql Downloading was good, until Installing collected packages: numpy, sqlalchemy, pandasql, pytz, six, python-dateutil Found existing installation: numpy 1.8.0rc1 DEPRECATION: Uninstalling a distutils installed project (numpy) has been deprecated and ...

 
11:14 AM
0
Q: For loop, how to reduece running time, pandas dataframe

Vince Date Open Close Buying Selling Cut_Off_Price 2009.11.11 4.805 4.43 0 0 0 2009.11.12 4.51 4.505 0 0 0 2009.11.13 4.545 4.765 1 0 3.812 2009.11.16 4.78 4.76 0 0 0 2009.11.17 4.755 4.605 0 0 0 2009.11.18 4.56 4.495...

 
11:32 AM
0
Q: Pandas: reindex with custom function

Vitali HalapjanI am looking for a way to reindex data with custom a function. My data looks as follows: AAA BBB CCC DDD Time 2009-01-30 09:30:00 6407.04 43.90 44.01 85.11 2009-01-30 09:39:00 6403.20 43.82 44.01 84.93 2009-01-3...

 
11:50 AM
0
Q: How do I use a mapping variable to re-index a dataframe?

bpythonI have the following data frame: population GDP country United Kingdom 4.5m 10m Spain 3m 8m France 2m 6m I also have the following information in a 2 column dataframe(happy for this to be made into another datastruct if ...

 
12:06 PM
0
Q: pandas.set_option to give detail of Dataframe rather than returning frame

whytheqI have a DataFrame called result. In the tutorial I'm watching Wes McKinney is getting the following return data when he executes a cell with just the name of the df in it - when I execute a cell with result in it I get the whole frame being returned. Is there a pandas set_option I can use to s...

0
Q: Writing a dictionary with name and numpy array data to text file issue

EloahI'm newbie in python and I'm coding some project. I need to save some data in dictionary format {name: numpy array} (and not only one dictionary) saving it to text file and then reading it from this file too. I use np.savetxt for this purpose. import numpy as np from DIP import dip name = 'n...

 
12:51 PM
0
Q: Strange lines in specgram using matplotlib

JakobovskiI am using matplotlib.specgram to create spectrograms of recordings of spoken words. For a reason unknown to me the spectrograms have strange lines in them as seen from the images below. I am wondering what is causing these lines and how can I get rid of them?

 
1:28 PM
0
Q: Python - why does eval fail on this string/expression?

espriI am running anaconda on OS X 10.11.5 and am struggling to access data in a pandas DataFrame. Doing it directly works fine but, when I try to evaluate arguments in a string which I have generated by iteration, it fails. Here is a simpler version that produces the same problem without the iteratio...

0
Q: Python/numpy: How do I find indices of selection of array

DeniseMy (very little piece of) code par = par[sel] sel_par = par[(par<=8) & (par>=1)] I want to know the indices of the array sel_par. par is also an array, so is sel_par. I only need the all indices but it gives the values. How do I do this? Thanks a lot!

0
Q: Find in which domain value is located

samer226047I have a numpy array like this x = [ [0,1],[1,2],[2,3],[3,4]] is there a built function in numpy that can get me in which domain my value is ? for example : np.find(3.5,x) return 3 (index of the domain ) ?

0
Q: Scikitklearns TfidfTransformer makes my pipeline predict just one label

durrruttiI have a pandas dataframe containing texts and labels, and I'm trying to predict the labels using scikit-learn's CountVectorizer, TfidfTransformer and MultinomialNB. Here's what the dataframe looks like: text party 0 Herr ålderspresident! Att vara...

 
 
1 hour later…
2:43 PM
0
Q: Unable to import ctypes on google-app-engine development server

MortCantySince upgrading from Ubuntu 14.04 to 16.04 I get the following error on the local development server: ERROR 2016-06-19 14:03:10,294 wsgi.py:263] Traceback (most recent call last): File "/home/mort/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handl...

 
3:17 PM
0
Q: ValueError: labels not contained in axis (pandas dataframe)

A. TiekI have got a pandas dataframe and I would like to convert it to a matrix, but I keep getting the same error.. My dataframe looks like this: 0 1 2 3 4 5 6 7 ... 0 id a p l k c f n ... 1 82 0.0 ...

 
3:34 PM
0
Q: memory exhaust on big matrix operation using dask

yusufazishtyCurrently I'm implementing this paper for my undergraduate theses with python, but I only use the mahalanobis metric learning (in case you're curious). In a shortcut, I face a problem when I need to learn a matrix with the size of 67K*67K consisting of integer, by simply numpy.dot(A.T,A) where ...

 
3:48 PM
0
Q: How to add error bars to interaction plot (statsmodels)?

LuisI have the following code: import numpy as np import matplotlib.pyplot as plt from statsmodels.graphics.factorplots import interaction_plot a = np.array( [ item for item in [ 'a1', 'a2', 'a3' ] for _ in range(30) ] ) b = np.array( [ item for _ in range(45) for item in [ 'b1', 'b2' ] ] ) mse = n...

0
Q: pandas conditional and not

MoritzI do select parts of my dataframe for fitting using a mask: mask = (data.conc == 50) & (data.id_exp == 'Pxxx') During the fit I found a probable outlier and would like to do something like mask = (data.conc == 50) & (data.id_exp == 'P049V208') and not (data.ratio == 10 & data.salt_concentrati...

 
4:15 PM
0
Q: Merging DataFrames on dates in chronological order in Pandas

Eric HansenI have about 50 DataFrames in a list that have a form like this, where the particular dates included in each DataFrame are not necessarily the same. >>> print(df1) Unnamed: 0 df1_name 0 2004/04/27 2.2700 1 2004/04/28 2.2800 2 200...

0
Q: Matplotlib pyplot lines are not drawn via animation

PvdLFor some reason I don't get any lines drawn in the code below. The goal is to plot the temperatures I get back over serial to a graph, time on X, temp on Y. $ python -c 'import matplotlib; import matplotlib.pyplot; print(matplotlib.backends.backend)' TkAgg $ python3 -c 'import matplotlib; import...

0
Q: How to resample dates with Pandas item by item?

ArijMy objective is to add rows in pandas in order to replace missing data with previous data and resample dates at the same time. Example : This is what I have : date wins losses 0 2015-12-19 11 5 1 2015-12-20 17 8 2 2015-12-20 10 6 3 2015-12-21 15 1 4 2015-12-25 11 5 5 ...

0
Q: Is my code inefficient or is my task hard?

Lodore66hope someone can help here? I've written some code to perform a look-up task, and it's taking a long time to do it––far longer than it seems it should. For confidentiality reasons, I can't describe the exact task, but I can give one that's directly analogous. Let's say that I have a database co...

 
4:35 PM
0
Q: numpy: setting duplicate values in a row to 0

Larry FreemanI am working on a scoring method that scores based on correct answers with three attempts. For each row, if the first attempt is right, the score is 1, if the second attempt is right, the score is 1/2, if the third attempt is right, the score is 1/3. The total score is the sum of the scores for...

0
Q: Create pandas DateTimeIndex from 12-hour-clock format

Vitali HalapjanI'm looking for a way to create a datetimeindex in pandas. My data looks as follows: Date Time AAA 0 06/17/2016 03:00:00 PM 19.13 1 06/17/2016 02:00:00 PM 19.13 2 06/17/2016 01:00:00 PM 19.26 3 06/17/2016 12:00:00 AM 19.28 4 06/17/2016 11:00:00 A...

 
4:47 PM
0
Q: Unable to install pandas on AWS Lambda

rtindruI'm trying to install and run pandas on an Amazon Lambda instance. I've used the recommended zip method of packaging my code file model_a.py and related python libraries (pip install pandas -t /path/to/dir/) and uploaded the zip to Lambda. When I try to run a test, this is the error message I get...

 
4:59 PM
-1
Q: Why we have to multiply by 2 the standard deviation?

AizzaacWhy does the "scoresSSS.std()" has to be multiplied by 2? Why not by 10 or divide it by 2? I am attaching some code. I am doing a 10 stratified shuffle split cross validation. In which case my accuracy is higher and more precise? print(scoresSSS) print("Accuracy SKF_NB: %0.2f (+/- %0.2f)...

 
5:41 PM
1
Q: Fixing antialising & line widths in matplotlib

kreyI'm trying to plot a binomial tree in matplotlib. I'm using matplotlib instead of something like the Python Imaging Library because I would like to have coordinate axes and ticks. S0 = 20 u = 1.04 d = 1/1.04 T = 0.5 N = 24 dt = T/N prices = [S0] fig = plt.figure(figsize=(20,15)) ax = fig.add_s...

0
Q: Search Indexer Transaction Safety

HSchmaleI am writing a search indexer for a site I built. It counts the number of times a word is used in a given story allowing one use of the word per chapter. I have also attempt to weight words in the titles and the descriptions more heavily by including them in every chapter that is indexed. I woul...

0
Q: pandas groupby resample unexpected result

piRSquaredSetup import pandas as pd df = pd.DataFrame({'grp': [1, 2] * 2, 'value': range(4)}, index=pd.Index(pd.date_range('2016-03-01', periods=7)[::2], name='Date') ).sort_values('grp') I wanted to group by 'grp' and resample my index daily, forward filling missing ...

 
5:59 PM
0
Q: Adding tooltip to multi line plot using mpld3

user1128088I'm a complete noob to web development. I was working on a flask app which plots multiline charts from pandas dataframe using matplotlib, but I wish to add tooltip to the data points via mpld3. mpld3tooltip example is only for scatter plots. How to do this for multiline plots? data = {'year': [2...

0
Q: multi bar plot using python where the number of columns change for every group?

steTI'm trying to make a multi bar plot using python and the table: x_name col_num value A 1 -0.62 A 2 -0.55 B 1 -0.66 B 2 -0.77 B 3 -0.72 I'd like to have a group of colums for evry unique x_label, values in col_num i...

0
Q: Error message saving DataFrame to_csv in iphython

Louis FloresI'm following Lesson 1 (http://nbviewer.jupyter.org/urls/bitbucket.org/hrojas/learn-pandas/raw/master/lessons/01%20-%20Lesson.ipynb) on using Pandas with the Jupyter console from Anaconda. I'm trying to export a DataFrame (dict) to a CSV file, here is my code, which matches the instruction in Le...

 
6:27 PM
0
Q: matplotlib.finance.candlestick2_ochl Not displaying colorup values from Pandas DataFrame

JackI am attempting to display some simple stock data. For some reason, I can't seem to get matplotlib.finance.candlestick2_ochl() to corectly display days where the stock price closed self.df['closep'] higher than it opened self.df['openp'] Not quite sure why I am getting this behaviour. I suspect ...

 
6:55 PM
0
Q: The best way to perform time gap analysis with Pandas?

FastidiousI'm trying to find the best way to approach a simple time gap analysis with Python and Pandas. This is just for fun, so feel free to explain answers to help me learn more. I started off by generating some random data. First is dates with a time stamp frequency of 20 seconds over the total period...

0
Q: Pickle interactive matplotlib figure

Henrik ViebrockI'm trying to pickle a figure and load it again. Everything seems to be fine but after I loaded the figure, I can see it from at least one point of view. In the original figure I can change the point of view. I tried an example to pickle like this: from mpl_toolkits.mplot3d import axes3d import...

 
7:27 PM
0
Q: Why does TensorFlow have a lot of mathematical equation re-implemented?

PinocchioI was looking through the API in TensorFlow and notice that a lot of mathematical operations that already exist in python and numpy have been re-implemented (or at least given a tensorflow interface). For example: is there a good reason to do this? I've been searching over their page but can'...

0
Q: How to groupby count across multiple columns in pandas

gtang31I have the following sample dataframe in Python pandas: +---+------+------+------+ | | col1 | col2 | col3 | +---+------+------+------+ | 0 | a | d | b | +---+------+------+------+ | 1 | a | c | b | +---+------+------+------+ | 2 | c | b | c | +---+------+------+-----...

 
7:44 PM
1
Q: Use loc and iloc together in pandas

Alexander WhatleySay I have the following dataframe, and I want to change the two elements in column "c" that correspond to the first two elements in column "a" that are equal to 1 to equal 2. >>> df = pd.DataFrame({"a" : [1,1,1,1,2,2,2,2], "b" : [2,3,1,4,5,6,7,2], "c" : [1,2,3,4,5,6,7,8]}) >>> df.loc[df["a"] ==...

 
8:01 PM
-1
Q: Neural network calculating wrongly

DelleinI'm trying to write a neural network in python but so far i think I'm missing something during the back propagation. Here is my code: import numpy as np import math from random import randint layers = [] class weights: def __init__(self, x,y,z): self.val = x self.oldDelt...

 
8:19 PM
0
Q: Cannot convert TIFF to an array

esw12345I have two datasets of .tif files. For data_1, I can convert the .tif images to arrays by using scipy.imread() and np.array. But for the other dataset data_2, when I apply the same functions, the .tif files are not converted to float arrays. data_1 = np.array([misc.imread(dir1+"/"+file) for subd...

 
8:34 PM
0
Q: Dataframe to .csv - is only writing last value - Python/Pandas

RageAgainstheMachineI'm trying to write a dataframe to a .csv using df.to_csv(). For some reason, its only writing the last value (data for the last ticker). It reads through a list of tickers (turtle, all tickers are in first column) and spits out price data for each ticker. I can print all the data without a probl...

 
8:46 PM
0
Q: OpenCV HSV value changes depending on location on the screen/camera

Vera MekernI'm pretty new to all programming and have been trying to get a grasp on Python (2.7.6), OpenCV, and ROS to be able to use a neural network in a robot. I am now stuck in an OpenCV (2.4.8) problem with getting the correct HSV-values, in short, it suddenly changes from red (around 5 for Hue) or b...

 
8:57 PM
0
Q: Seaborn histogram with 4 panels (2 x 2) in Python

O.rkaI'm trying to recreate this image using sklearn.datasets.load_iris and seaborn. I really like the idea of doing fig, ax = plt.subplots() and then using seaborn's ax=ax attribute. I can't figure out how to recreate this plot: I checked on stackoverflow and found this but it overlays them How T...

 
9:25 PM
0
Q: Add 3 columns to DataFrame via map

whytheqIs it possible to add 3 new columns to this little DataFrame in one map? import datetime as dt import pandas as pd from pandas import * df = pd.DataFrame({'myDate':['2006-02-12' ,'2007-07-20' ,'2009-05-19']}) def convert_date(val): ...

0
Q: Pandas vectorized operations not working on large dataset

Jack ArnoI ran the following code and found it to be working as expected on rather small datasets, but not on large ones. You can try it for yourself: import pandas as pd import numpy as np # generating dataframe of one million observations observations = 1000000 df = pd.DataFrame(np.random.randint(0,10...

 
@ScottCraner give me 2 secs...
1 message moved from VBA Lounge
 
9:43 PM
1
Q: Turn array into array of arrays following structure of another array

user2520932I would like to turn an array into an array of arrays following another array of arrays. I'm not sure how to do this, here are the arrays: orig_array = [[0,1],[4],[3],[],[3,2,6],[]] my_array = [0,1,2,3,4,5,6] wanted_array = [[0,1],[2],[3],[],[4,5,6],[]] I would like to keep the empty arrays....

1
Q: Django BigIntegerField getting corrupted by Angular but not by CURL?

Saqib AliI have created a Django REST API using Django Rest Framework. I use 3 different clients to hit this app: Curl (for debugging purposes) Swagger Interface (for debugging purposes) My Angular application I have a perplexing problem that data returned by the API is being corrupted by Swagger and...

 
10:18 PM
0
Q: Python lazy dict with iterable in constructor

Eirik FullerThis question began as an off-topic answer to this question, but the code here serves a different goal. I wrote the following class for the purpose of populating a dict on demand from an iterable. The intent of the iterable passed to the constructor is that it could alternatively be passed to di...

 
10:32 PM
0
Q: klein script CSS isn't working

Cristian I have a very simple klein script that is just a reverse-proxy: from klein import run, route, Klein from twisted.web.proxy import ReverseProxyResource @route('/') def home(request, branch=True): return ReverseProxyResource('www.example.com', 80, ''.encode('utf-8')) run("MY_IP", 80) The o...

0
Q: Python NumbaPro GPU vectorization with Error : TypingError: Failed at nopython (nopython frontend)

Gavin RockwoodI am trying to use numbapro to run a basic simulation of object interactions. But I am getting this error and im not sure what the problem is. I am pretty new with trying to do GPU acceleration :( Here is my code: from turtle import * import numpy as np from numbapro import vectorize setup( ...

0
Q: pandas subset and drop rows based on column value

rameshmy df: dframe = pd.DataFrame({"A":list("aaaabbbbccc"), "C":range(1,12)}, index=range(1,12)) Out[9]: A C 1 a 1 2 a 2 3 a 3 4 a 4 5 b 5 6 b 6 7 b 7 8 b 8 9 c 9 10 c 10 11 c 11 to subset based on column value: In[11]: first = dframe.loc[dframe["A...

 
11:23 PM
0
Q: How to avoid AnnotationBbox image being clipped in matplotlib subplot

Will GearyI'm plotting NYC water consumption overtime and am trying to annotate the plot with red heat wave images hovering over each year where there was a drought. However, the heat wave image is layered beneath the plot and is being clipped. How can I "bring forward" the heatwave image so that is fully...

 
11:45 PM
0
Q: Plotting a wire frame sphere using MatPlotLib

KarnivaurusUsing MatPlotLib, I want to draw a sphere by plotting a set of spherical coordinates. I have got halfway there, but I cannot quite achieve what I want exactly. So far, the following code: import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as axes3d theta, phi...

 

« first day (848 days earlier)      last day (1340 days later) »