indexing

R: Get indices of all elements in a vector?

南笙酒味 提交于 2021-02-05 12:37:59
问题 Simple questions, but I can't find an answer. I have a vector a<-c(5,6,7) how can I get back the indices for all elements in my vector? I need back 1 #"a" 2 #"b" 3 #"c" or c(1,2,3) If I run seq_along(a), it gives me back (1,1,1) not (1,2,3) : for (i in seq_along(a)) { print(seq_along(a[[i]])) } [1] 1 [1] 1 [1] 1 The reason for this is that I need to create a unique name for each of my plots. I have about 100 plots illustrating 100 locations. Locations'names are too long and contain special

R: Get indices of all elements in a vector?

六月ゝ 毕业季﹏ 提交于 2021-02-05 12:34:38
问题 Simple questions, but I can't find an answer. I have a vector a<-c(5,6,7) how can I get back the indices for all elements in my vector? I need back 1 #"a" 2 #"b" 3 #"c" or c(1,2,3) If I run seq_along(a), it gives me back (1,1,1) not (1,2,3) : for (i in seq_along(a)) { print(seq_along(a[[i]])) } [1] 1 [1] 1 [1] 1 The reason for this is that I need to create a unique name for each of my plots. I have about 100 plots illustrating 100 locations. Locations'names are too long and contain special

IndexError: string index out of range on equation cleaning function

老子叫甜甜 提交于 2021-02-05 10:36:03
问题 I have code to append ^0 to all the constants in my code so that if you had the string "3x^2+14+2" it would become "3x^2+14^0+2^0" however I am getting a IndexError and I have no idea what I am doing wrong. This is my code: def cleanEquation(equation): equation = ''.join(equation.split()) for i in range(len(equation)): if equation[i].isdigit(): if equation[i-1] != "^": if i == len(equation)-1: equation = equation[:i+1] + '^0' if equation[i+1] == "+" or equation[i+1] == "-": equation =

IndexError: string index out of range on equation cleaning function

被刻印的时光 ゝ 提交于 2021-02-05 10:32:40
问题 I have code to append ^0 to all the constants in my code so that if you had the string "3x^2+14+2" it would become "3x^2+14^0+2^0" however I am getting a IndexError and I have no idea what I am doing wrong. This is my code: def cleanEquation(equation): equation = ''.join(equation.split()) for i in range(len(equation)): if equation[i].isdigit(): if equation[i-1] != "^": if i == len(equation)-1: equation = equation[:i+1] + '^0' if equation[i+1] == "+" or equation[i+1] == "-": equation =

Is there a way to exclude NULL values from Azure Cognitive Search Indexes

心不动则不痛 提交于 2021-02-05 08:44:30
问题 So for example we have field 1 up to 10. I want to index all the field in Azure Search, so you can filter, search on those filters. My Question is, is there a way to just exclude the fields that are NULL from a specific ID, so not store them in Azure search? See example underneath. The data itself is initially stored in Azure Cosmos Database. In Azure Cosmos DB it would like this: Id 1 field 1: a field 2: b field 5: c field 6: d field 8: e Id 2 field 3: a field 2: b field 5: c field 9: d

How to delete specific rows in excel with openpyxl python if condition is met

对着背影说爱祢 提交于 2021-02-05 07:48:16
问题 Using openpyxl I am creating python script that will loop through the rows of data and find rows in which some of the column are empty - these will be deleted. The range of rows is 3 to 1800. I am not excatly sure how to delete these row - please see code I have come up with so far. What I was trying to achieve is to iterate through the rows and check if columns 4, 7 values are set to None. If True I wanted to return row number into suitable collection (need advise which one would be best for

How to delete specific rows in excel with openpyxl python if condition is met

妖精的绣舞 提交于 2021-02-05 07:47:07
问题 Using openpyxl I am creating python script that will loop through the rows of data and find rows in which some of the column are empty - these will be deleted. The range of rows is 3 to 1800. I am not excatly sure how to delete these row - please see code I have come up with so far. What I was trying to achieve is to iterate through the rows and check if columns 4, 7 values are set to None. If True I wanted to return row number into suitable collection (need advise which one would be best for

Pandas: Change values chosen by boolean indexing in a column without getting a warning

走远了吗. 提交于 2021-02-05 03:21:02
问题 I have a dataframe, I want to change only those values of a column where another column fulfills a certain condition. I'm trying to do this with iloc at the moment and it either does not work or I'm getting that annoying warning: A value is trying to be set on a copy of a slice from a DataFrame Example: import pandas as pd DF = pd.DataFrame({'A':[1,1,2,1,2,2,1,2,1],'B':['a','a','b','c','x','t','i','x','b']}) Doing one of those DF['B'].iloc[:][DF['A'] == 1] = 'X' DF.iloc[:]['B'][DF['A'] == 1]

Pandas: Change values chosen by boolean indexing in a column without getting a warning

烂漫一生 提交于 2021-02-05 03:16:06
问题 I have a dataframe, I want to change only those values of a column where another column fulfills a certain condition. I'm trying to do this with iloc at the moment and it either does not work or I'm getting that annoying warning: A value is trying to be set on a copy of a slice from a DataFrame Example: import pandas as pd DF = pd.DataFrame({'A':[1,1,2,1,2,2,1,2,1],'B':['a','a','b','c','x','t','i','x','b']}) Doing one of those DF['B'].iloc[:][DF['A'] == 1] = 'X' DF.iloc[:]['B'][DF['A'] == 1]

converting the index of 1D array into 2D array

妖精的绣舞 提交于 2021-02-04 21:37:18
问题 How can I convert the index of 1D array into 2D array? I know how to convert a 2D array into 1D (i*the size of row+j) . I want the opposite of that. 回答1: What you need to know is: How many columns should the 2D array have: Lets say you have an array of 20 columns and 10 rows (array[20,10]): int index = 47; int numberOfColumns = 20; int column = index % numberOfColumns; int row = index / numberOfColumns; // column == 7 // row == 2 回答2: You can just do the opposite. if n is the length of the