« first day (847 days earlier)      last day (1341 days later) » 

12:45 AM
0
Q: Emulating nested for loop with scan is slow

TFUserI am trying to convolve over an image with a special (bilateral) filter all while using Tensorflow control ops so I can use automatic differentiation. To accomplish this, I nested scan() functions, but this leaves me with remarkably poor performance---a small image takes more than 5 minutes. Is t...

 
1:21 AM
0
Q: Create Numpy Array Representing a Geometric Shape

ChildishJackAs the title suggests, how would one create a numpy array of 3D coordinates of a geometric shape? Currently, I have the easiest shape already figured out: latva = 6 latvb = 6 latvc = 6 latdiv = 20 lol = np.zeros((latdiv**3,4),dtype=np.float64) lol[:,:3] = (np.arange(latdiv**3)[:,None]//(latdiv...

 
 
2 hours later…
2:58 AM
0
Q: Efficient way to merge two files with same "column name" and "different rows"

Bhishan PoudelI have two datafiles a.csv and b.csv which can be obtained from pastebin: http://pastebin.com/nzjXESYn http://pastebin.com/PDV5Ah64 First file a.csv has 4 columns and some comments: # coating file for detector A/R # column 1 is the angle of incidence (degrees) # column 2 is the wavelength (mi...

 
3:32 AM
0
Q: Split and Join Series in Pandas

noblerthanoedipusI have two series in the dataframe below. The first is a string which will appear in the second, which will be a url string. What I want to do is change the first series by concatenating on extra characters, and have that change applied onto the second string. import pandas as pd #import urlpar...

0
Q: Python web crawler

UnChapelierFouHey all I wrote a shity python web crawler #!/usr/bin/python import threading import urllib import Queue from bs4 import BeautifulSoup import sys import time import signal visited_urls = [] crawl_lock = threading.RLock() class crawler(threading.Thread): def __init__(self, url_given, cr...

 
4:04 AM
0
Q: Python - IF for a column in panda datafram

Square9627I would like to turn NaN values in the column GP in the dataframe draft (which has 22 rows) into 0. I tried these lines but they dont work import pandas as pd draft = pd.read_csv('Draft year.csv') if draft['GP'].isnull(): draft['GP'] = 0 In R there is ifelse which does the job nicely but...

 
4:29 AM
0
Q: Simple script hangs creating and/or saving figure with matplotlib

GabrielI'm running Python 2.7.11+ and matplotlib 1.5.1 on Ubuntu 16.04 64 bit. The very simple script shown below hangs at either of the three lines marked. If I leave all lines un-commented, it will hang on the first one. If I comment it out, it will hang on the second one. Same with the third one. N...

 
 
2 hours later…
6:03 AM
0
Q: Pandas extract multiple columns

Michał MalusUsing Pandas I am adding new columns to a DataFrame: df["Year"] = df["concat"].str.extract("(\d\d\d\d$)", expand=False) df["Month"] = df["concat"].str.extract("(\d\d)\_\d\d\d\d$", expand=False) df["Measure"] = df["concat"].str.extract("^(.*)\_\d\d\_\d\d\d\d$", expand=False) This works but is v...

 
6:32 AM
0
Q: How to make pandas dataframe str.contains search faster

Toussaint LouvertureI'm searching for a substring or multiple substrings in the dataframe of 4 million rows. df[df.col.str.contains('Donald',case=True,na=False)] or df[df.col.str.contains('Donald|Trump|Dump',case=True,na=False)] DataFrame(df) looks like below (with 4 million string rows) df = pd.DataFrame({'...

 
7:02 AM
0
Q: Tilted grid network plotting in Basemap

Han ZhengzuHere is an example figure as illustration. This plot present the satellite SO2 column data for part of Europe. Due to the difference between satellite and longitude, the grid network which fit the satellite scanning principle are not parallel to longitude. I don't know if it's possi...

 
7:58 AM
0
Q: How to merge dataframes using pandas python?

Sai Rajeshi have following two dataframes data1 company,values a,76 b,56 c,78 d,56 dataframe2 company,comp_id a,a1 b,b1 i need output like following format company,value,comp_id a,76,a1 b,56,b1 c,78 d,56 how to merge dataframes like following format?

 
8:16 AM
0
Q: Lookup values with different column names in pandas

Square9627I have 2 pandas dataframes df1 and df2 Name No A 1 A 2 B 5 Player Gender A F B M C F I would like to create a new column sex in the df1 dataframe, using corresponding values from the column gender in df2. The columns used to look up are Name in df1 and Player i...

0
Q: I want to change the format of my DataFrame in pandas. How can I do this?

Gil BaggioMy current dataframe looks like this: In [40]: result Out[40]: monthyear Facility Date Yield Planned 0 Dec 15 CCM2 2015-12-01 2550.000000 0.0 1 Feb 16 CCM2 2016-02-01 4250.000000 0.0 2 Jan 16 CCM1 2016-01-01 1540.000000 0.0 3 Jan 16 ...

 
8:27 AM
0
Q: How to assign value to a scalar variable in numpy array?

user5779223I wrote a for-loop and wished to assign the value to the first variable in the part of an array that equals to -inf. The complete code is as below: cList = np.full((5), -np.inf) for i in range(5): newest = another_array[i][1] cList[cList==-np.inf][0] = newest The code didn't throw any ...

0
Q: How to rename a column which have a same name with another one

aaaaa0aI have an data - frame as below... AA BB CC DD EE ... LL MM NN NN 0 a0 b0 c0 d0 e0 ... l0 m0 x0 y0 1 a1 b1 c1 d1 e1 ... l1 m1 x1 y1 2 a2 b2 c2 d2 e2 ... l2 m2 x2 y2 3 a3 b3 c3 d3 e3 ... l3 m3 x3 y3 I would like to change the name of 'NN' which is in right edge. Somebody says you should use ...

 
8:55 AM
0
Q: how to create url column dataframe using two column values in python pandas?

Sai Rajeshi have following dataframe. company,compid,secid a,a1,a2 b,b1,b2 i need output like following format company,compid,secid,url a,a1,a2,http://www.cssss.com/companydetails.aspx?compid=a1&secid=a2 b,b1,b2,http://www.cssss.com/companydetails.aspx?compid=b1&secid=b2 how to ...

 
9:32 AM
0
Q: Why is Django's returning stale cache data?

Saqib AliI have two Django models as shown below, MyModel1 & MyModel2: class MyModel1(CachingMixin, MPTTModel): name = models.CharField(null=False, blank=False, max_length=255) objects = CachingManager() def __str__(self): return "; ".join(["ID: %s" % self.pk, "name: %s" % self.name,...

 
 
2 hours later…
11:09 AM
0
Q: quesrions regarding hurst exponent code in python 3

vincent chenWhen I run this code in Python 3,why it shows name “lags” not defined? from numpy import log,sqrt,std,subtract,cumsum,polyfit def hurst(ts): # Create the range of lag values lags = range(2, 100) # Calculate the array of the variances of the lagged differences tau = [sqrt(std(sub...

 
12:00 PM
0
Q: How to write a pandas DataFrame that contain UUID to excel using xlsxwriter?

ludofetI'm trying to write a DataFrame to excel using xlsxwriter. I get the following error: "TypeError: Unsupported type <class 'uuid.UUID'> in write()" I can work around the issue by converting the UUID into string myself but I feel it could be done better that that. The code that generates the ...

 
12:29 PM
0
Q: Forward (or Backward filling) in postgres

Guillaume ThomasThe problem is to fill missing values in a table. In pandas, one can use forward (or backward) filling to do so as shown below: $> import pandas as pd $> df = pd.DataFrame({'x': [None, 1, None, None, 2, None, 3, None]}) $> df x y 0 NaN NaN 1 1 1 2 NaN 1 3 NaN 1 4 2 2 5 NaN 2 ...

 
12:40 PM
0
Q: Appending elements generated by a for loop into an array

nikjohnI want to generate an array containing all the elements produced by a for loop. I haven't found anything relevant or helpful in the NumPy manual or stackoverflow. This is the problematic part of the code. import numpy as np for i in range(0,26): d = np.random.uniform(i,i+1.75) empty = n...

0
Q: How to re-order my Pandas dataframe other than using the "columns.tolist()" method?

Gil Baggiomy dataframe is like this: In [57]: final_data Out[57]: monthyear Date Planned CCM1 CCM2 0 Dec 15 2015-12-01 0.0 0.000000 2550.000000 1 Feb 16 2016-02-01 0.0 0.000000 4250.000000 2 Jan 16 2016-01-01 0.0 1540...

 
12:52 PM
0
Q: Pandas make new column from substring slice based on the number in a substring of another column

amcI have a dataframe called 'table' like this: import pandas as pd import numpy as np table = pd.read_csv(main_data, sep='\t') And it produces this: NAME SYMBOL STRING A blah A34SA B foo BS2812D ... How can I create a new column in pandas so I have the follow...

 
1:03 PM
@PraveenKumar These are available commands in this room see also quick guide for usage.
Guest
    api-quota - Get the current api quota
    commands - Display this list
    help - Display information about the chat bot
Reviewer
    remove - Remove last message or message replied to
Hammer
    k - Confirm that possible duplicate is closed
    list tags - List all tags available for opt-in in room
    f <wl> - Indicate as non duplicate if wl add also to white list
    opt-in [tag] - Add yourself to duplication notifications in tag of choice
    opt-out [tag] - Remove yourself from duplication notifications in tag
 
2 messages moved from SO Close Vote Reviewers
 
- (IBAction)closeBtnMth:(id)sender{
UITabBarController *tbc=(UITabBarController*)[self.storyboard instantiateViewControllerWithIdentifier:@"TabbarController"];
if([InterestVC interestVCisFromWelcomeScene]){
[self.navigationController pushViewController:tbc animated:YES];
}
else{
tbc.selectedIndex = 0;

}
}
 
0
Q: Modify timestamps to sequence per ID

Tobias121I have a Pandas dataframe (Python 3.5.1) with a timestamp column and an ID column. Timestamp ID 0 2016-04-01T00:15:36.688 123 1 2016-04-01T00:12:52.688 123 2 2016-04-01T00:35:41.688 543 3 2016-04-01T00:01:12.688 543 4 2016-03-31T23:50:59.688 123 5 2016-0...

 
1:19 PM
1 message moved from iOS Developer Family
 
1:41 PM
0
Q: get python pandas to_dict with orient='records' but without float cast

user3313834I have a dataframe with one col int one col floats: df # a b # 0 3 42.00 # 1 2 3.14 df.dtypes # a int64 # b float64 # dtype: object I want a list of dicts like the one provide by df.to_dict(orient='records') df.to_dict(orient='records') [{'a': 3.0, 'b': 42.0}, {'a': 2.0,...

 
1:58 PM
0
Q: Set of matrices

BasjI have lots of matrices (as result of rotations, etc.), but I would be sure to store them only once. I thought about using a set : print set([np.matrix([[0, 0],[0, 1],[1, 1],[2, 1]]), np.matrix([[0, 0],[1, 0],[1, -1],[1, -2]])]) Unfortunately, I get : TypeError: unhashable type: 'matrix'...

0
Q: using an numpy array as indices of the 2nd dim of another array?

loganecolssFor example, I have two numpy arrays, A = np.array( [[0,1], [2,3], [4,5]]) B = np.array( [[1], [0], [1]], dtype='int') and I want to extract one element from each row of A, and that element is indexed by B, so I want the following results: C = np.array( [[1], [2], [5...

 
2:11 PM
0
Q: Rotation of a bitmap matrix

BasjLet A be a 3x3 matrix (of black and white pixels) : A = np.matrix([[0, 0, 0], [0, 1, 1], [0, 0, 1]]) corresponding to 0 0 0 0 1 1 0 0 1 How to perform a 90° rotation with the centre being the middle "1" of the matrix ?

0
Q: Fractional Knapsack Solution in Python

Huy VoI made a solution for fractional knapsack problem in Python. Fractional knapsack is pretty classical: given a set of items and total capacity of a knapsack, find the maximal value of fractions of items that fit into the knapsack. Input Format: The first line of the input contains the number n of...

0
Q: Shorter version of this numpy matrix indexing

off99555I have the following code in python (numpy or scipy.sparse.matrices), it works: X[a,:][:,b] But it doesn't look elegant. 'a' and 'b' are 1-D boolean mask. 'a' has the same length as X.shape[0] and 'b' has the same length as X.shape[1] I tried X[a,b] but it doesn't work. How would you make t...

 
3:01 PM
0
Q: Convert a list of values to a time series in python

user308827I want to convert the foll. data: jan_1 jan_15 feb_1 feb_15 mar_1 mar_15 apr_1 apr_15 may_1 may_15 jun_1 jun_15 jul_1 jul_15 aug_1 aug_15 sep_1 sep_15 oct_1 oct_15 nov_1 nov_15 dec_1 dec_15 0 0 0 0 0 1 1 2 2 ...

 
3:30 PM
0
Q: HackerRank "Lists" code

zthomas.ncI completed the following exercise on HackerRank. My program is fed a list of commands, such as: 12 insert 0 5 insert 1 10 insert 0 6 print remove 6 append 9 append 1 sort print pop reverse print Where the first line of the input is the number of commands, the rest of the lines commands and...

0
Q: Having problems feeding data to tensorflow graph

Marcelo VassermanI am trying to adjust the MNIST2 problem in tensorflow tutorial to train a neural network using my own images. But I am having problems feeding data to the graph. My code: from __future__ import absolute_import from __future__ import division from __future__ import print_function import os.path...

0
Q: unpack tuple containing datetime

comteI have a function f(date, level), I want to unpack arguments from a numpy.record or a tuple print(tuple(row)) (datetime.datetime(2016, 6, 17, 18, 57, 00, tzinfo=+2), 123) but print(*tuple(row)) 2016-06-17 18:57:00+02:00 123 which is 3 arguments to my function, so error. how to keep first tu...

 
4:32 PM
0
Q: useing regular expression for column filter

forvaidyaI have a DF contain year and title. some rows.name are like Batman, Catman I am trying to get all rows matching .*aman using following expression.. t[t.title & re.search(r'.*man', t.title)] This Fails. Is the idiomatic way to accomplish above ?

 
4:46 PM
0
Q: autoscaling not working on drawing arrow

awhanTrying to draw a simple arrow in Matplotlib using the following: import matplotlib.pyplot as plt fig, ax = plt.subplots() ax.arrow(1, 1, 1, 1) plt.show() which results in an empty plot. If the arrow specifications are changed to ax.arrow(0, 0, 1, 1) then I do see an arrow in the final plot. S...

 
5:00 PM
0
Q: sum of primefactors of binomial coefficients over 9000

N3buchadnezzarThe problem I have lately been working Project Euler: 231: The prime factorisation of binomial coefficients The binomial coefficient \$ ^{10}C_3 = 120 \$. \$ 120 = 23 × 3 × 5 = 2 × 2 × 2 × 3 × 5 \$, and \$ 2 + 2 + 2 + 3 + 5 = 14 \$. So the sum of the terms in the prime fac...

 
5:10 PM
0
Q: Pandas: Charting 3 months of quotes with a benchmark

vsolerI have a df with the daily "Adj Close" (from Yahoo) for many stocks that I want to chart compared to the SPY. AAPL ABC ... SPY Date 2016-03-10 100.56 85.79 198.52 2016-03-11 101.64 89.14 201.72 ... 2016-06-09 99.65 76.17 212.08 2016-06-10 98.8...

 
5:31 PM
0
Q: Pandas Dataframe: Splitting a list of predictions into dataframe columns

Larry FreemanI am using a scikit-learn model (kdtree) to make predictions. Originally, I was trying to only take the top 3 which is done using the following code given a fitted model (clf), list of labels (labels), and test data (test): _,neighbors = clf.query(select_columns(test),k=30) top3 = [Counter([l...

0
Q: Balancing dependence/independence of packages

TomHow does one determine what classes and functions belong in the same package? I have a large Python package that I sense should be split into multiple packages. For example, there is currently a subpackage for GIS processes, a subpackage for tabular processes, and a subpackage for processes/data...

 
 
1 hour later…
6:50 PM
0
Q: Attaching multiple plots to a seaborn plot

ResMarThe following bit of code: import seaborn as sns sns.lmplot(x='EstCurentMarketValueSqFt', y='MarketValueSqFt', data=sales, scatter_kws={'edgecolor': "black", 'linewidth': 1}) Generates the following picture: However, I would like to a...

0
Q: A prefix notation calculator that asks about everything step by step

zyabin101I made a prefix notation calculator. Prefix notation, aka Polish notation, is a form of notation for logic, arithmetic and algebra, like infix and postfix (reverse Polish) notation. The expression '+ 3 4' in prefix notation is as valid as '3 + 4' in infix notation, as well as '3 4 +' in postfix...

 
7:05 PM
0
Q: HackerRank “Save Humanity”

Dhiwakar RavikumarThere's a problem on Hackerrank titled "Save Humanity". I've pasted the link to the problem below. In a nutshell, it requires me to compare two strings and find the beginning index value for all occurrences of the second substring in the first. The catch is that upto one mismatch in the substrin...

0
Q: Error importing matplotlib

hiyWhen I try to import matplotlib in python 2.7 I get the following error: ➜ ~ python Python 2.7.10 (default, Jul 14 2015, 19:46:27) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import matplotlib Trace...

 
7:26 PM
0
Q: Printing dataframe to .csv in python. TypeError:must be convertible to a buffer

RageAgainstheMachineI'm going through a dataframe and appending specific rows into a list. I'm then taking that list and trying to save it as a .csv file. However, I'm getting the following error: TypeError: must be convertible to a buffer, not DataFrame. Any suggestions on what this is and how to fix this is great...

 
7:40 PM
0
Q: SparkStreaming, RabbitMQ and MQTT in python using pika

NavonodJust to make things tricky, I'd like to consume messages from the rabbitMQ queue. Now I know there is a plugin for MQTT on rabbit (https://www.rabbitmq.com/mqtt.html). However I cannot seem to make an example work where Spark consumes a message that has been produced from pika. For example I a...

 
8:17 PM
0
Q: Faster way to extract patches from images?

Avijit DasguptaI am trying to extract patches of fixed size centered at some given position (x,y). The code is given below- for i,j in zip(indices[0],indices[1]): patches.append( x[None, i-int(np.floor(patch_size/2.0)):i+int(np.floor(patch_size/2.0))+1, j-int(np.floor(patch_size...

 
8:54 PM
-1
Q: How lambda works in Python

user3854325I have a Dataframe as: States = ['NY', 'NY', 'NY', 'NY', 'FL', 'FL', 'GA', 'GA', 'FL', 'FL'] data = [1.0, 2, 3, 4, 5, 6, 7, 8, 9, 10] idx = pd.date_range('1/1/2012', periods=10, freq='MS') df = pd.DataFrame(data, index=idx, columns=['Revenue']) df['State'] = States But, I don't understand ...

 
9:32 PM
0
Q: Segmentation fault 11 when using matplotlib to plot

Jason WangWhen I run a very simple python plot code (shown as follow), the segmentation fault 11 error comes out. import matplotlib.pyplot as plt plt.plot([1,2,3,4]) It is quite weird. I run this code in mac terminal. The python is from Enthought canopy_64bit, version 2.7. The matplotlib's version is 1.5...

 
9:48 PM
0
Q: Numpy save taking too long in large dataset

pepeI'm trying to save a numpy array to disk but the saving process never seems to end, and the terminal keeps hanging without showing me the final print message of 'done'. I can tell the array is correctly formed by checking its shape right before the saving function. I wonder if I'm doing anything ...

 
10:17 PM
0
Q: Why the Kalman Filter works uncorrectly?

AndreyI work on the project where I need to filter the values marked in blue on the picture with Kalman Filter. But I don`t understand, what went wrong is. So will be VERY glad if you look at my code and describe the mistake(s). The incorrect result picture (The Kalman filter measurements are green):...

 
10:32 PM
0
Q: updating prior rows of dataframe conditionally upon current

user3784793I have a dataframe (ev), and I would like to read it and whenever the value of the 'trig' column is 64, I need to update the value of the critical column that is 4 rows above, and change it to 999. I tried the code below but it does not change anything, though seems it should work. for i in rang...

0
Q: Python - applying concat function for two rows in pandas data frame

Sreejith MenonI have a large data frame which is basically an image id and a set of biological features. I have to combine all the IDs(the GIDs) and the resulting features should be concatenation of all the rows with the same ID. I do understand the solution will require use of group_by function with an apply...

 
11:15 PM
0
Q: How do I use seaborns color_palette as a colormap in matplotlib?

CorrumpoSeaborn offers a function called color_palette, which allows you to easily create new color_palettes for plots. colors = ["#67E568","#257F27","#08420D","#FFF000","#FFB62B","#E56124","#E53E30","#7F2353","#F911FF","#9F8CA6"] color_palette = sns.color_palette(colors) I want to transform color_pa...

0
Q: How to remove noise from a white region, without losing the shape of the white region

MetalHere's the image: I want to remove the noise within the white region without losing the shape of the white region. I've tried dilation, but that effects the shape of the white region. I've also tried dilation followed by erosion, and it's the same problem - the shape of the white region gets a...

 

« first day (847 days earlier)      last day (1341 days later) »