Latest Questions tagged Indexing

Browse all latest questions tagged Indexing

69
Votes
Published 27 Oct, 2022
Java - How to use different tablespaces for tables and indexes with liquibase in Java

I'm using liquibase (3.6.3) in Spring Boot (2.1.8) java (1.8) application for managing database (Oracle 12.2) schema changes. My liquibase changesets does not contain 'tablespace' params and all data...

70
Votes
Published 20 Aug, 2022
Python - How to compare two data frame and get the unmatched rows using python?

I have two data frames, df1 and df2. Now, df1 contains 6 records and df2 contains 4 records. I want to get the unmatched records out of it. I tried it but getting an error ValueError: Can only compare...

6
Votes
Published 01 May, 2022
Python - Insert element in Python list after every nth element

Say I have a Python list like this: letters = ['a','b','c','d','e','f','g','h','i','j'] I want to insert an 'x' after every nth element, let's say three characters in that list. The result should b...

7
Votes
Published 21 Aug, 2022
Python - Remove rows of a dataframe based on the row number

Suppose that I have a data-frame (DF) and also I have an array like this: rm_indexes = np.array([1, 2, 3, 4, 34, 100, 154, 155, 199]) I want to remove row numbers in rm_indexes from DF. One in rm_ind...

94
Votes
Published 11 Jun, 2022
Python - Python: Removing Rows on Count condition

I have a problem filtering a pandas dataframe. city NYC NYC NYC NYC SYD SYD SEL SEL ... df.city.value_counts() I would like to remove rows of cities that has less than 4 count frequency, w...

76
Votes
Published 26 Apr, 2022
Python - Start index at 1 for Pandas DataFrame

I need the index to start at 1 rather than 0 when writing a Pandas DataFrame to CSV. Here's an example: In [1]: import pandas as pd In [2]: result = pd.DataFrame({'Count': [83, 19, 20]}) In [3]: r...

75
Votes
Published 31 May, 2022
Python - Find all positions in a NumPy array that contain a substring (most efficient?)

I want to find all indices in an array that contain a substring, in this case it is substring = "contig_". I started iterating line by line and then iterating through each element in the array but th...

6
Votes
Published 04 Jun, 2022
Python - Use loc and iloc together in pandas

Say I have the following dataframe, and I want to change the two elements in column c that correspond to the first two elements in column a that are equal to 1 to equal 2. >>> df = pd.DataFr...

6
Votes
Published 02 Jun, 2022
Python - Pandas using loc for assignment in a Multi Index DataFrame

I have initialised a dataframe like this: df = pd.DataFrame(columns=["stockname","timestamp","price","volume"]) df.timestamp = pd.to_datetime(df.timestamp, format = "%Y-%m-%d %H:%M:%S:%f") df.set_ind...

70
Votes
Published 19 Aug, 2022
Python - Pytorch batch indexing

So the output of my network looks like this: output = tensor([[[ 0.0868, -0.2623], [ 0.0716, -0.2668], [ 0.0584, -0.2549], [ 0.0482, -0.2386], [ 0.0410, -0.2234], [ 0.0362, -...

97
Votes
Published 26 Jul, 2022
Python - Performance of various numpy fancy indexing methods, also with numba

Since for my program fast indexing of Numpy arrays is quite necessary and fancy indexing doesn't have a good reputation considering performance, I decided to make a few tests. Especially since Numba i...

25
Votes
Published 20 Jun, 2022
Python - Pandas pivot_table, sort values by columns

I am a new user to Pandas and I love it! I am trying to create a pivot table in Pandas. Once I have pivot table the way I want, I would like to rank the values by the columns. I've attached an image...

101
Votes
Published 20 Aug, 2022
Python - pandas time series multiple slice

I can see from the pandas documentation that you can go: df.loc[['a','b','c'],:] For time series, why can you not go: x = df.loc[['2005-10-27 14:30':'2005-10-27 15:15', '2006-04-14 14:40':'2006-04...

65
Votes
Published 19 Aug, 2022
Python - Indexing a list of vectors in python

I have a loop that is creating vectors v_1, v_2, ... , v_n. So far, the way I 'index' them is by creating an array list_of_vectors=(v_1,v_2,...,v_n) and whenever I want to call one of them, I retrieve...

102
Votes
Published 28 Aug, 2022
Python - Pandas indexing and Key error

Consider the following: d = {'a': 0.0, 'b': 1.0, 'c': 2.0} e = pd.Series(d, index = ['a', 'b', 'c']) df = pd.DataFrame({ 'A' : 1.,'B' : e,'C' :pd.Timestamp('20130102')}). When i try to access the...