if-statement

Python break down a super long IF statement

Deadly 提交于 2020-01-15 03:25:26
问题 How to simplify or break down the super long IF Condition in Python pandas? my_dataframes = {'d1': d1, 'd2': d2,'d3': d3} good_dataframes = [] for df_name, df in my_dataframes.items(): if ((df.loc[1:4, 'test'] <= 6).all() and (df.loc[5:9, 'dif'] < 9).all()) or ((df.loc[1:5, 'test'] <= 6).all() and (df.loc[5:8, 'dif'] < 8).all()) or ((df.loc[1:8, 'test'] <= 6).all() and (df.loc[5:8, 'dif'] < 9).all()): good_dataframes.append(df_name) the challenge for me is put the right indent 回答1: you can

How can i create a new column that inserts the cell value of grouped column 'ID' (in time) when 'interaction' is 1

谁都会走 提交于 2020-01-15 03:16:28
问题 I have three relevant columns: time, id, and interaction. How can i create a new column with the id values that have a '1' in column 'interaction' in the given time window? Should look something like this: time id vec_len quadrant interaction Paired with 1 3271 0.9 7 0 1 3229 0.1 0 0 1 4228 0.5 0 0 1 2778 -0.3 5 0 2 4228 0.2 0 0 2 3271 0.1 6 0 2 3229 -0.7 5 1 [2778, 4228] 2 3229 -0.3 2 0 2 4228 -0.8 5 1 [2778, 3229] 2 2778 -0.6 5 1 [4228, 3229] 3 4228 0.2 0 0 3 3271 0.1 6 0 3 4228 -0.7 5 1

Python - Call a Function on a Condition

蓝咒 提交于 2020-01-14 14:47:08
问题 I was wondering if there is a concise way to call a function on a condition. I have this: if list_1 != []: some_dataframe_df = myfunction() I'm wondering if it is possible to this in a ternary operator or something similiar. If I do (some_dataframe_df = myfunction()) if list_1 != [] else pass It doesn't work. 回答1: Your code is fine. The only change I suggest is to use the inherent Truthness of non-empty lists: if list_1: some_dataframe_df = myfunction() If you wish to use a ternary statement

Nested IF statements with exact OR values

五迷三道 提交于 2020-01-14 14:08:41
问题 I'm new to Excel IF statements and am having trouble with what I believe is called a nested IF function . I've looked at other IF questions on here and they're too complicated for my novice brain to understand. I have a column that has numbers in it. There are about a dozen different numbers. The numbers represent a specific team. For example, 100 is team red, 101 is team yellow, 102 is team green, etc. I need to create an IF statement that will tell me what each of the teams are based on the

Insert data if number of rows is greater than 0 does not work

五迷三道 提交于 2020-01-14 06:52:10
问题 I have this PHP function which will insert urls into MySQL, but only those which didn't exist until moment of executing. I have a problem, my if condition is simply ignored, so everything goes to database, ignoring the condition. Code is here: function storeLink($url,$gathered_from) { global $conn; $querycheck = "SELECT COUNT(*) FROM test WHERE link = '$url'"; $resultcheck = mysqli_query($conn, $querycheck); $row = mysqli_fetch_array($resultcheck, MYSQLI_ASSOC); if($row['COUNT(*)'] < 1); {

How to convert String to Boolean Logic? [duplicate]

那年仲夏 提交于 2020-01-14 05:43:13
问题 This question already has answers here : Safely evaluate simple string equation (2 answers) Evaluating a mathematical expression in a string (11 answers) Closed 2 years ago . I have sting input like: 12 == 21 (10 != 12) or (15 == 13) True and (10 == 10) And i need to return boolean value of this input. Can i convert it using exec() or bool() ? I don't want to write big method to solve it . 来源: https://stackoverflow.com/questions/53675559/how-to-convert-string-to-boolean-logic

Java : Recursion -While Loop Vs If Loop

爱⌒轻易说出口 提交于 2020-01-14 05:17:13
问题 Code Design 1 : works perfectly public static void main (String[] args) { recursion(2); } public static void recursion(int num) { if (num > 0) { recursion( num - 1 ); System.out.println(num); } } Code Design 2 : Infinite Loop. ? public static void main (String[] args) { recursion(2); } public static void recursion(int num) { if (num == 0) return; while (num > 0) { recursion( num - 1 ); System.out.println(num); } } Can someone plz help me in understanding why 2nd design is getting into

How to test if the first three characters in a string are letters or numbers in r?

倾然丶 夕夏残阳落幕 提交于 2020-01-14 03:47:10
问题 The example of the dataset I have is given below, note that I have more than two columns in the total dataset. ID X 1 MJF34 2 GA249D 3 DEW235R 4 4SDFR3 5 DAS3 I want to test whether the first three characters in X are letters, if they are then I want to replace that value to show only the first three letters. If the first three characters aren't letters then I want to replace those values with "FR". Hence the result would be as follows. ID X 1 MJF 2 FR 3 DEW 4 FR 5 DAS Currently X is a

Adding multiple integer ranges of values from a column in the ifelse statement in R

一世执手 提交于 2020-01-14 02:38:06
问题 I am dealing with genomic data and I have columns on nucleotide position and its conservation score (in a dataframe). I have data regarding which range of nucleotide positions are introns and which are exons. I want to create a third column and be able to specify which regions are introns (as "INTRON") and which are exons (as "EXON"). As an example suppose in nucleotide positions 1-70000, I want to specify 10000-10200, 17800-21000, 43000-54000 as introns and remaining as exons in another

Rolling a circle around a square

我与影子孤独终老i 提交于 2020-01-13 12:16:28
问题 After almost a month I am still stuck on this issue I managed to decide whether the circles (or pedestrians as I call them) should move left/right or up/down but I need to have the possibility to move the pedestrians around a building (that means they have to turn on the corners, basically does not matter whether direction, they just need to turn by 90 degrees Thank you very much import numpy as np import random import keyboard from Box2D.b2 import world, polygonShape, circleShape, edgeShape,