for-loop

How to name dataframes with a for loop?

帅比萌擦擦* 提交于 2020-02-23 07:15:24
问题 I want to read several files json files and write them to a dataframe with a for-loop. review_categories = ["beauty", "pet"] for i in review_categories: filename = "D:\\Library\\reviews_{}.json".format(i) output = pd.read_json(path_or_buf=filename, lines=True) return output The problem is I want each review category to have its own variable, like a dataframe called "beauty_reviews", and another called "pet_reviews", containing the data read from reviews_beauty.json and reviews_pet.json

How do I group items in an array by date?

梦想与她 提交于 2020-02-21 11:25:36
问题 Given the following array of objects: [ { "notes": "Game was played", "time": "2017-10-04T20:24:30+00:00", "sport": "hockey", "owner": "steve", "players": "10", "game_id": 1, }, { "notes": "Game was played", "time": "2017-10-04T12:35:30+00:00", "sport": "lacrosse", "owner": "steve", "players": "6", "game_id": 2, }, { "notes": "Game was played", "time": "2017-10-14T20:32:30+00:00", "sport": "hockey", "owner": "steve", "players": "4", "game_id": 3, }, { "notes": "Game was played", "time": "2017

How do I group items in an array by date?

限于喜欢 提交于 2020-02-21 11:23:22
问题 Given the following array of objects: [ { "notes": "Game was played", "time": "2017-10-04T20:24:30+00:00", "sport": "hockey", "owner": "steve", "players": "10", "game_id": 1, }, { "notes": "Game was played", "time": "2017-10-04T12:35:30+00:00", "sport": "lacrosse", "owner": "steve", "players": "6", "game_id": 2, }, { "notes": "Game was played", "time": "2017-10-14T20:32:30+00:00", "sport": "hockey", "owner": "steve", "players": "4", "game_id": 3, }, { "notes": "Game was played", "time": "2017

how to convert 2d array into 1d?

北城余情 提交于 2020-02-21 06:00:06
问题 i have a code that create 2d array using user input and it work fine but now i have 2 questions the first one: how to convert 2d array to 1d array? second question: how to choose or trace the elements above the right diagonal in the 2d array? anyone can help me to fix this code? this my code package question3; import java.util.Arrays; import java.util.Collection; import java.util.Scanner; public class Array2d { public static void main(String[] args) { int[][] matrix = new int[3][3]; int[]

how to convert 2d array into 1d?

我们两清 提交于 2020-02-21 05:59:25
问题 i have a code that create 2d array using user input and it work fine but now i have 2 questions the first one: how to convert 2d array to 1d array? second question: how to choose or trace the elements above the right diagonal in the 2d array? anyone can help me to fix this code? this my code package question3; import java.util.Arrays; import java.util.Collection; import java.util.Scanner; public class Array2d { public static void main(String[] args) { int[][] matrix = new int[3][3]; int[]

how to convert 2d array into 1d?

旧巷老猫 提交于 2020-02-21 05:58:26
问题 i have a code that create 2d array using user input and it work fine but now i have 2 questions the first one: how to convert 2d array to 1d array? second question: how to choose or trace the elements above the right diagonal in the 2d array? anyone can help me to fix this code? this my code package question3; import java.util.Arrays; import java.util.Collection; import java.util.Scanner; public class Array2d { public static void main(String[] args) { int[][] matrix = new int[3][3]; int[]

refactoring when two functions share some similarity

我与影子孤独终老i 提交于 2020-02-15 23:07:20
问题 I have two tabs in my app one is a player tab and another is a coaching tab. I have a function1 in the player tab and function2 in the coaching tab. function1 var beforeList = $('#players').val() $('#players').change(function () { var afterList = $(this).val() var selectedPlayer = '' if (!beforeList) { selectedPlayer = afterList[0] $('parent option[value=' + selectedPlayer + ']').add() $('#injuredPlayer option[value=' + selectedPlayer + ']').add() } else if (!afterList) { selectedPlayer =

How do I insert multiple value if there is only one value in form

本秂侑毒 提交于 2020-02-08 02:58:29
问题 I need to know how can I insert or update a value in my DB for a invoice form if the value of the input that I need to save is only one time? I have a invoice form where I select a product in every row, and finally I have the input(user_id) with the value I need to save with the rest of the inputs Like per example, I choose in the invoice: 10 tomatoes 5 garlics 2 beans and finally there is my Id (user_id, not the Id of PRODUCTOS table that is unique) Id=1 Here is the schema of my table, and

How to use a value outside for loop

隐身守侯 提交于 2020-02-07 06:46:04
问题 In the following code i need the value of varArray[i] for executing the if-else statements but the if-else statements are to be executed only once. If i place the if-else statements outside the for loop the if-else statements do execute correctly. When i place the if-else statement inside the for loop the if-else statements get executed multiple times. for (int i=0;i<varArray.length;i++) { varArray[i]= rand.nextInt(1999)-1000; System.out.println(varArray[i]); if(d==varArray[i]) { System.out

Split lists and tuples in Python

十年热恋 提交于 2020-02-07 02:37:29
问题 I have a simple question. I have list, or a tuple, and I want to split it into many lists (or tuples) that contain the same elements. I'll try to be more clear using an example: (1,1,2,2,3,3,4) --> (1,1),(2,2),(3,3),(4,) (1,2,3,3,3,3) --> (1,),(2,),(3,3,3,3) [2,2,3,3,2,3] --> [2,2],[3,3],[2],[3] How can I do? I know that tuples and lists do not have the attribute "split" so i thought that i could turn them into strings before. This is what i tried: def splitt(l) x=str(l) for i in range (len(x