AlanH

1

votes
1

answer
31

views

How to drop records in a data frame where data is missing in exactly the desired columns?

In the docs, it is shown that using subset will drop rows where if a cell in any of the listed columns has missing data. However, I want to drop data only if there is missing data in ALL the columns I list (not to be confused with all the columns I have in my data frame). So to be extra clear: born...
AlanH
1

votes
2

answer
29

views

Pandas: How to only convert values in a column that are not None?

pandas NaT value is giving me a lot of trouble. As a workaround, I'd like to only convert my Timestamps() only if they are not None. That way, I do not end up with NaTs in these columns. I have not found a way to apply df.check_in = pd.to_datetime(pd.check_in) only to non-None values though. Origina...
AlanH
1

votes
1

answer
695

views

Using Matlab function `trisurf` to display results

I've obtained a solution, u from Gauss-Siedel (solving 2D Poisson's equation), and I want to plot it using trisurf. I can't, however, seem to understand how trisurf works (I have tried playing around with it, but with no luck). I've also taken a look at the Matlab documentation, but I don't understa...
AlanH
1

votes
3

answer
92

views

Attribute Error in Python. How to use match and group? [duplicate]

This question already has an answer here: Python regular expressions, how to search for a word starting with uppercase? 1 answer I'm trying to get the following to work. I've looked at the Python documentation, and I still don't know how to fix it. I'm getting an AttributeError, what am I doing wro...
AlanH
1

votes
1

answer
1.7k

views

How to print first row of a file as a list? [duplicate]

This question already has an answer here: How to read one single line of csv data in Python? 5 answers I need to grab the first row of a .csv file (the headers), and return it as a list. I tried something like this: import csv with open('some.csv', 'rb') as f: reader = csv.reader(f) for row in rea...
AlanH
1

votes
2

answer
71

views

Need help writing custom filter function in JavaScript

I've written an each() function, which works correctly, that behaves exactly the same as underscore's _.each(). I'd like to write a function that's sort of similar to filter(), but instead returns true or false for each element that is run through the callback/predicate function. var filter = functi...
AlanH
1

votes
2

answer
41

views

How to have border-radius only on last box? [closed]

I have a 'container' which has border-radius of 5px for the bottom left and right corners. Within the container are stacked boxes or div's. All of the div's are the same size, and they fill up the entire container. However, the very last div looks to be conflicting with the border-radius of the las...
AlanH
1

votes
2

answer
65

views

How to submit text area by clicking submit button OR by hitting Enter?

Currently I can only submit my textarea by clicking on the submit button. I've also seen multiple posts, such as this one, on how submit the form by hitting Enter. However, I'd like to know if there was a way to implement both in one function. Currently, I have: $('form[name=userForm]').on('submit',...
AlanH
1

votes
2

answer
38

views

Need help understanding mergeSort and apply()

I'm new to js and I'm trying to understand how apply is used here (I've been struggling with trying to understand apply as of late). However, my issue is two-fold. While I understand the overview of mergesort, but I have no idea what is happening in the last block. function mergeSort(items){ if (it...
AlanH
1

votes
1

answer
271

views

How to apply an eslint git hook?

I'm not familiar with git hooks, and I've tried following the git docs, but I've had no luck implementing this eslint pre-commit hook. Below is a screen shot of what I've done. When I git add a file, then try to commit it, all I get is: [eslint-experimental 123123abc] some_message 1 fele changed, 10...
AlanH
1

votes
2

answer
52

views

How to make the starting height of two columns the same?

In my demo (http://jsfiddle.net/pdExf/864/), the starting position of the fourth element is higher than that of the first. How do I fix this? Snippet: span { margin-left: 14px; flex: 1 1 auto; overflow: 'hidden'; word-wrap: break-word; /* white-space: -moz-pre-wrap !important; */ /* Mozilla, s...
AlanH
1

votes
3

answer
65

views

How to use the rest and spread operators together in a function definition?

I have the following: const a = (...args) =>{ return {...args}} const abc = a('lol', 'rofl', 'lmao'); console.log('abc', abc); However, this prints out Object {0: 'lol', 1: 'rofl', 2: 'lmao'} But I expected Object {lol: 'lol', rofl: 'rofl', lmao: 'lmao'} since {lol, rofl, lmao} produces the line abo...
AlanH
1

votes
1

answer
42

views

How to add to a casted list in a HashMap?

I have a Map, and one of the values is a List. Currently, I have: if (!data.containsKey(myVar)) { List emp = new ArrayList(); data.put(myVar, emp); // myVar is a String } else { data.get(myVar).add(otherVar); // 'add' gives an error; otherVar is a String } My current solution is to do } else { @Sup...
AlanH
1

votes
1

answer
62

views

How to translate pythonic double for loop to standard code?

I have this chunk of pythonic code that I've been having trouble understanding: paths = [[end]] while paths and paths[0][0] != start: paths = [[parent] + path for path in paths for parent in childToParents[path[0]]] where childToParents is: defaultdict(, {'cog': {'log', 'dog'}, 'dog': {'dot'}, 'dot'...
AlanH
1

votes
1

answer
0

views

Python - How to view *all* HTTP connections coming in/out of my machine?

I know of the library requests, and urllib, and logging. However, from the examples I've perused, I can only seem to find the example where you specify a specific example - e.g. - requests.get('https://httpbin.org/headers'). Is there any way to continuously and actively monitor all incoming/outgoing...
AlanH
1

votes
2

answer
0

views

How to have two different sort orders within the same list? [duplicate]

This question already has an answer here: Sort a list by multiple attributes? 4 answers I have a sorted list such as [[1, 'start'], [13, 'start'], [13, 'end'], [15, 'end']] which is the output of my_list.sort(key=lambda x: x[0]). However, if there is a tie with the 0th element of each sub-list, as...
AlanH
1

votes
1

answer
5.4k

views

Creating a grid figure in Matlab with coordinates labelled

How do I write a function in Matlab to generate an nxn grid? I'm working on a numerical problem and I'm getting quite tired of drawing very large grids by hand -- extremeley tedious and impractical, but without this I would have a hard time progressing through the problem. Essentially I would need t...
AlanH
1

votes
2

answer
55

views

Getting matplotlib to work - plots not showing

I was able to successfully install matplotlib; however, when I run my code, I don't get an error, but instead the Python icon bouncing over and over again. I don't know if it has anything to do with from rcParamsSettings import * I don't have any idea what that is, but if I try to run it with that...
AlanH
1

votes
2

answer
50

views

R: obtaining subset of a column that matches a certain criteria

Let's say I have a table of data of all the students in a school. I want to look at family size of students who are male (1) and are at least considered 'tall'. How would I do this in R? I only can seem to figure out how to get the column of family size of students, which would be student_data$famil...
AlanH
1

votes
2

answer
47

views

Having difficulty obtaining subset in R

I'm trying to subset a data set with the following requirements: ethnicity is xyz education is Bachelor's Degree and above, i.e. Bachelor's Degree or Graduate Degree I then want to look at the income bracket of those who meet the above requirements. A bracket would be something like $30,000 - $39,99...
AlanH
0

votes
0

answer
5

views

Visual Studio- How to view call heirarchy/graph/stack without running code?

In these recent docs, it seems that VS is able to show the call graph/hierarchy of calls to a function. However, in the most recent version of VS, I can't seem to be able to find this. Is this now somewhere else or is there an extension that does something like this?
AlanH
1

votes
2

answer
30

views

How does a link that requires authentication work?

Suppose I sign in to Facebook and I'm looking at a private event. I want to send that link to my friend so that he can join the event. However, doing so requires my friend to log in to Facebook (to be authenticated), so that he can view the event and join it. In other words: I'm logged in, and am on...
AlanH
1

votes
2

answer
53

views

Python: Why does heap give incorrect first pop?

I'm trying to create a max heap by negating all the values of a list, but it doesn't seem to be working: import heapq x = range(1,10) neg = [-n for n in x] heapq.heappop(neg) # -1 heapq.heappop(neg) # -9 heapq.heappop(neg) # -8 Yet if I do heapq.heappop(x) # 1 heapq.heappop(x) # 2 heapq.heappop(x) #...
AlanH
1

votes
1

answer
1k

views

Docker cannot build because can't find matching distribution of a requirement

I'm having difficulty getting my app on Docker. Currently I'm trying to build build it, but am running in to an error I can't figure out how to solve. When I ran docker-compose build, it was pulling and downloading, but when it tried to collect json, it gave the error: Could not find a version that...
AlanH
1

votes
4

answer
5.9k

views

How to check if a function has been called? jQuery

I've been given a script, which I cannot edit (as a part of an exercise). In the script, there is a function which generates random messages for a set of given [fake] users. (It's supposed to emulate a chat room). I need to detect when a message has been generated. As of now, the only thing I can th...
AlanH
1

votes
1

answer
93

views

Python: Unable to kill process with keyboard interrupt?

I have a decorator written as such: import threading from time import sleep from functools import wraps import sys import os def repeat_periodically(f): ''' Repeat wrapped function every second ''' @wraps(f) def wrap(self, *args, **kwargs): def wrap_helper(*args, **kwargs): try: threading.Timer(1.0,...
AlanH
0

votes
0

answer
3

views

Pytest not collecting tests with pytest command

I have in my Project/tests/learn_pytest.py a basic test. This is everything in the file: import pytest import os class Learning(object): def create_file(self): p = tmpdir.mkdir('sub').join('hello.txt') p.write('content') print tmpdir.listdir() assert p.read() == 'content' assert len(tmpdir.listdir()...
AlanH
1

votes
2

answer
195

views

Python: What does the following code do?

Can someone please explain to me piece by piece, what the following does? My code won't run and this part was provided. I've tested all of my code in iPython notebook and everything works, so I don't know if the problem is because of this block below. def main(): args = sys.argv[1:] if not args: pr...
AlanH
1

votes
3

answer
793

views

Pandas: How to create a column based on values of another column?

I need to create a new column at the end of a data frame, where the values in that new column are the result of applying some function who's parameters are based on other columns. Specifically, from another column, but a different row. So for example, if my data frame had two columns, containing val...
AlanH
1

votes
3

answer
72

views

How to loop over properties of objects at the same time in Javascript?

I'm trying to figure out how to loop over two objects at the same time so that I can compare their properties. What I tried was something like for ((prop1, prop2) in (obj1, obj2) { console.log(prop1 == prop2) } which definitely didn't work. How do I do this in js?
AlanH
1

votes
4

answer
99

views

How to understand this example of a logical and ternary operator?

I understand that ternary operators are essentially a shortcut for an if-else statement, and I also understand that && is a logical AND. However, I don't understand how the two are combined in the code below. I tried playing around with the output as well, but it didn't help. How do I interpret the...
AlanH
1

votes
1

answer
228

views

Excel VBA form TextBox passed as an Arguement

I'm trying to pass a TextBox created on a form to a subroutine to inspect the contents of the TextBox and limit the TextBox to numeric data only. Since VBA doesn't have overloading I'm using optional parameters to call the function without any parameters as part of TextBox_Exit event or as a standa...
AlanH
3

votes
4

answer
1.1k

views

How to ignore re-render after store changes?

I have a few components where I outright want to ignore a re-render (or any other change to those components) if certain parts of the store change. How can this be done?
AlanH
2

votes
2

answer
1.8k

views
2

votes
2

answer
39

views

Python Regular expression: is there a symbol to search for more than one occurence of a pattern?

I know that * is 0 or more, and + is 1 or more, but what if I wanted to indicate 2 or more (more than 1)? For example, I have >>> y = 'U0_0, P33, AVG' >>> re.findall(r'[a-zA-Z]+', y) ['U', 'P', 'AVG'] But I only want to obtain ones that have 2 or more letters. In this example, AVG. How do I do thi...
AlanH
5

votes
2

answer
3.1k

views

How to cancel ALL requests in ComponentWillUnmount?

According to the docs, ComponentWillUnmount is able to cancel requests. I have a page that makes requests for an iframe to load, as well as other requests for page. If the user decides to navigate away from the page while the page is still processing the requests, how can I cancel those requests so...
AlanH
6

votes
4

answer
2.3k

views

Avoiding inline functions in React: How to bind functions with arguments?

I'm trying to follow the no-bind rule for React using the pattern that they have recommended with ES6 classes: class Foo extends React.Component { constructor() { super(); this._onClick = this._onClick.bind(this); } render() { return ( Hello! ); } _onClick() { // Do whatever you like, referencing 't...
AlanH
5

votes
4

answer
396

views

Git: How does checking out affect the repository?

I'm not at all experienced with programming, and I'm just starting to learn Git. I don't understand how git checkout works. According to this: Checking out an old commit is a read-only operation. It’s impossible to harm your repository while viewing an old revision. The “current” state of your...
AlanH
8

votes
1

answer
598

views

Python pandas: conditionally select a uniform sample from a dataframe

Say I have a dataframe as such category1 category2 other_col another_col .... a 1 a 2 a 2 a 3 a 3 a 1 b 10 b 10 b 10 b 11 b 11 b 11 I want to obtain a sample from my dataframe so...
AlanH
2

votes
1

answer
32

views

R: How to obtain corresponding column of values?

Let's say I have three columns A, B, and C. I've taken a subset of A (say every other row), how do I obtain the corresponding values of those rows in C? A B C 1 a1 a1 c1 2 a2 b2 c2 3 a3 b3 c3 4 a4 b4 c4 I want: A C 1 a1 c1 2 a3 c3 Note: using every other row for the subse...
AlanH

View additional