Posts

Showing posts from July 8, 2018

How to collapse multiple columns into one in pandas

How to collapse multiple columns into one in pandas I have a pandas dataframe filled with users and categories, but multiple columns for those categories. | user | category | val1 | val2 | val3 | | ------ | ------------------| -----| ---- | ---- | | user 1 | c1 | 3 | NA | None | | user 1 | c2 | NA | 4 | None | | user 1 | c3 | NA | NA | 7 | | user 2 | c1 | 5 | NA | None | | user 2 | c2 | NA | 7 | None | | user 2 | c3 | NA | NA | 2 | I want to get it so the values are compressed into a single column. | user | category | value| | ------ | ------------------| -----| | user 1 | c1 | 3 | | user 1 | c2 | 4 | | user 1 | c3 | 7 | | user 2 | c1 | 5 | | user 2 | c2 | 7 | | user 2 | c3 | 2 | Ultimately, to get a matrix like the foll

Fatal error in launcher: Unable to create process using “”C:Program Files (x86)Python33python.exe“ ”C:Program Files (x86)Python33pip.exe“”

Fatal error in launcher: Unable to create process using “”C:Program Files (x86)Python33python.exe“ ”C:Program Files (x86)Python33pip.exe“” Searching the net this seems to be a problem caused by spaces in the Python installation path. How do I get pip to work without having to reinstall everything in a path without spaces ? pip Have you tried using short path names for program files(X86)? e.g. "C:PROGRA~2Python33python.exe" – Shadow9043 Jul 8 '14 at 8:55 The problem is that when pip is installed, it will use the original, long name it gets from the system. See my answer below. – Archimedix Jul 9 '14 at 9:57 pip Reproducable with Python 2.7 and Windo

Is there a way to use pg_trgm like operator with btree indexes on PostgreSQL?

Is there a way to use pg_trgm like operator with btree indexes on PostgreSQL? I have two tables: ref_id_t1 is filled with id_t1 values , however they are not linked by a foreign key as table_2 doesn't know about table_1. I need to do a request on both table like the following: SELECT * FROM table_1 t1 WHERE t1.c1_t1= 'A' AND t1.id_t1 IN (SELECT t2.ref_id_t1 FROM table_2 t2 WHERE t2.c1_t2 LIKE '%abc%'); Without any change or with basic indexes the request takes about a minute to complete as a sequencial scan is peformed on table_2. To prevent this I created a GIN idex with gin_trgm_ops option: CREATE EXTENSION pg_trgm; CREATE INDEX c1_t2_gin_index ON table_2 USING gin (c1_t2, gin_trgm_ops); However this does not solve the problem as the inner request still takes a very long time. EXPLAIN ANALYSE SELECT t2.ref_id_t1 FROM table_2 t2 WHERE t2.c1_t2 LIKE '%abc%' Gives the following Bitmap Heap Scan on table_2 t2 (cost=664.20..189671.00 rows=65058 width=4) (actual

Validate date field on focusout with jquery-validation

Validate date field on focusout with jquery-validation Date Input Field not valid, When first time selecting the date. Its showing required error message, because of field have an empty value( check console log ). But field will be valid on second change. Notes: A cause is that date input field loses focus when picking the date (click event). But the date populates only later changed when the click event happens. But validator will validate field on focus out event. I'm validating a form using Jquery Validation, using bootstrap-datepicker for Widget. ^^for Better UX Run code snippet on full-page ;) or jsfiddle from @Sparky / @Vignesh ans: Yes, its a workaround for this, We can use change/hide/changeDate(module attribute) event handler. It gets triggered once the input values have been set. But the problem is whenever we pick from year->month->date each clicks in the picker, removes focus from input and focusout event fired and showing the error message until choosing

python google geolocation api using wifi mac

python google geolocation api using wifi mac I'm trying to use Google's API for geolocation giving wifi data to determine location. This is their intro. And this is my code @author: Keith """ import requests payload = { "considerIp": "false", "wifiAccessPoints": [ { "macAddress": "00:25:9c:cf:1c:ac", "signalStrength": -43, "signalToNoiseRatio": 0 }, { "macAddress": "00:25:9c:cf:1c:ad", "signalStrength": -55, "signalToNoiseRatio": 0 } ], 'key':'<MyAPIKey>' } r = requests.post('https://www.googleapis.com/geolocation/v1/geolocate', params=payload) print(r.text) This is the output { "location": { "lat": 32.3643098, "lng": -88.703656 }, "accuracy": 6061.0 } The request ignored all of the payload except t

Socket connection in background

Socket connection in background I need to make an application where, while the user is authorized, it keeps the socket connection until it is logged out. For this purpose, a foreground service is created, which starts after the authorization of the user, and stops when it is logged out. It implements connection and reconnection on the socket. All works well until you press the power button and turn off the charging. After this, the user stops receiving pongs from the server and the SocketTimeoutException is received on the OkHttp, and also stops receiving messages on the socket. On JavaWebsocket The connection was closed because the other endpoint did not respond with a pong in time. is received, after which you can successfully create a new socket connection, but it will repeat the same problem in the loop. In the settings, the optimization of the battery for this application was disabled. What can I do to make a stable connection socket work in the background? Implementation of acti

How does Firebase Cloud Messaging calculate the amount of notifications sent?

How does Firebase Cloud Messaging calculate the amount of notifications sent? Specifically, does it automatically remove users who disabled notifications? Does it count users who uninstalled the app? I couldn't find any info on the docs. 1 Answer 1 Firebase Cloud Messaging will try to deliver messages to all users that you target. So no matter if the users disabled the notifications on their phone, they will still be counted as messages that were sent. Of course, those users will not actually receive the message, so they will not count as messages that were received/opened. I have currently way more users than the messages that are sent when I select the whole app (1.8k users vs 1.3k users). Where can I trace back the difference? Uninstalls? – XelharK Jul 3 at 15:39

How to manage Numpy arrays in Pandas DataFrames

How to manage Numpy arrays in Pandas DataFrames Let's assume one has a DataFrame with some integers values and some arrays defined somehow: df = pd.DataFrame(np.random.randint(0,100,size=(5, 1)), columns=['rand_int']) array_a = np.arange(5) array_b = np.arange(7) df['array_a'] = df['rand_int'].apply(lambda x: array_a[:x]) df['array_b'] = df['rand_int'].apply(lambda x: array_b[:x]) Some questions which can help me understand how to manage Numpy arrays with Pandas DataFrames: array_diff So you want to multiply both array a and array b by the corresponding value in rand_int? – user3483203 Jul 2 at 7:20 Not only that, but also define another column in df which is the np.setdiff1d between the rows in array_a and array_b . Thank you – espogian

How to generate JSON examples from OpenAPI/Swagger model definition?

How to generate JSON examples from OpenAPI/Swagger model definition? I'm building a fuzzer for a REST API that has an OpenAPI (Swagger) definition. I want to test all available path from the OpenAPI definition, generate data to test the servers, analyse responses code and content, and to verify if the responses are conform to the API definition. I'm looking for a way to generate data (JSON object) from model definitions. For example, given this model: ... "Pet": { "type": "object", "required": [ "name", "photoUrls" ], "properties": { "id": { "type": "integer", "format": "int64" }, "category": { "$ref": "#/definitions/Category" }, "name": { "type": "string", "example": "doggie" }, "photoUrls": {

Avoid repeated columns from a select statement

Avoid repeated columns from a select statement My database contains a table person with these fields username, name, online, visible, ... person username, name, online, visible, ... I have the following query to fetch the person SELECT *, CASE WHEN online = 0 THEN 0 WHEN visible = 0 THEN 0 ELSE online END AS online FROM person where id = SOMEID I am trying to move the online/offline with respect to user-set visibility logic right into the query. Basically show online status depending on visibility status (If the user has chosen to be invisible, show offline even if the user is online). This kind of works but with an issue. I get two repeated columns in the result of this query. username | name | online | visible | ... | online x | x | x | x | ... | x For reasons not in my control I am stuck with using SELECT * instead of manually typing in the columns as SELECT username, name, visible, ... . Is there a way to exclude online field

Material-UI ExpansionPanelSummary expanded class

Material-UI ExpansionPanelSummary expanded class In the documentation for Material-UI ExpansionPanelSummary there are several class override names where expanded is one of them. Could someone explain why it is not possible to use the following code to set the size of the root as well as expanded state? <ExpansionPanelSummary classes={{ root: { midWidth: 30}, expanded: { minWidth: 30} }}> foo bar </ExpansionPanelSummary> 1 Answer 1 you need to follow the styles overriding methods as the material-ui suggested. please find methods from here: https://material-ui.com/customization/overrides/ here I used classes overriding using withStyles from material ui const styles = theme => ({ root: { minWidth: 300 }, heading: { fontSize: theme.typography.pxToRem(15), fontWeight: theme.typography.fontWeightRegular }, expanded: { minWidth: 30, backgroundColor: "red" }

Spark's Column.isin function does not take List

Spark's Column.isin function does not take List I am trying to filter out rows from my Spark Dataframe. val sequence = Seq(1,2,3,4,5) df.filter(df("column").isin(sequence)) Unfortunately, I get an unsupported literal type error java.lang.RuntimeException: Unsupported literal type class scala.collection.immutable.$colon$colon List(1,2,3,4,5) according to the documentation it takes a scala.collection.Seq list I guess I don't want a literal? Then what can I take in, some sort of wrapper class? 2 Answers 2 @JustinPihony's answer is correct but it's incomplete. The isin function takes a repeated parameter for argument, so you'll need to pass it as so : isin scala> val df = sc.parallelize(Seq(1,2,3,4,5,6,7,8,9)).toDF("column") // df: org.apache.spark.sql.DataFrame = [column: int] scala> val sequence = Seq(1,2,3,4,5) // sequence: Seq[Int] = List(1, 2, 3, 4, 5

Couchbase Lite alternative [closed]

Couchbase Lite alternative [closed] I have an Android project whose use CouchBase lite 1.4 with CouchDB .We want to use the last CouchBase lite version but I have been reading this in the documentation about CouchBase Lite 2.0 : Android CouchBase lite 1.4 CouchDB CouchBase lite CouchBase Lite 2.0 The new protocol is incompatible with CouchDB-based databases. And since Couchbase Lite 2 only supports the new protocol, you will need to run a version of Sync Gateway that supports it. So I guess I have to migrate to Sync Gateway ?¿ as I can read here: Couchbase Lite 2.0's enhanced replication protocol is not compatible with CouchDB. The Sync Gateway 2.0 however will supporting both Couchbase Lite 2.0 mobile clients with the new protocol and the CouchDB enabled replication protocol. My problem is that I have not clear what is Sync GatAway,becouse in some places you can read that works with CouchDB in other place I can read that does not work. This question appears to be of