Questions tagged [indexing]

Indexing data structures is a general technique to improve the speed of data lookups.

The purpose of storing an index is to optimize speed and performance in finding relevant documents for a search query. Without an index, the search process would scan every document in the corpus, which would require considerable time and computing power.

Indexes may benefit both read queries and updates. Many people wrongly believe indexes are only good for read queries. In general, there are three methods of indexing - non-clustered, clustered and cluster.

References:

Top Indexing Questions

By these questions, you will clear your concepts regarding indexing. And you can ask similar questions (not duplicate) with this tag.

33955 questions
4319
votes
44 answers

Finding the index of an item in a list

Given a list ["foo", "bar", "baz"] and an item in the list "bar", how do I get its index 1?
Eugene M
  • 47,557
  • 14
  • 38
  • 44
2863
votes
7 answers

How does database indexing work?

Given that indexing is so important as your data set increases in size, can someone explain how indexing works at a database-agnostic level? For information on queries to index a field, check out How do I index a database column.
Xenph Yan
  • 83,019
  • 16
  • 48
  • 55
2709
votes
25 answers

How do I get the last element of a list?

How do I get the last element of a list? Which way is preferred? alist[-1] alist[len(alist) - 1]
Janusz
  • 187,060
  • 113
  • 301
  • 369
2204
votes
18 answers

How to remove an element from a list by index

How do I remove an element from a list by index? I found list.remove(), but this slowly scans the list for an item by value.
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
1700
votes
24 answers

Selecting multiple columns in a Pandas dataframe

How do I select columns a and b from df, and save them into a new dataframe df1? index a b c 1 2 3 4 2 3 4 5 Unsuccessful attempt: df1 = df['a':'b'] df1 = df.ix[:, 'a':'b']
user1234440
  • 22,521
  • 18
  • 61
  • 103
1278
votes
12 answers

What do Clustered and Non-Clustered index actually mean?

I have a limited exposure to DB and have only used DB as an application programmer. I want to know about Clustered and Non clustered indexes. I googled and what I found was : A clustered index is a special type of index that reorders the way …
P.K
  • 18,587
  • 11
  • 45
  • 51
918
votes
7 answers

How are iloc and loc different?

Can someone explain how these two methods of slicing are different? I've seen the docs and I've seen previous similar questions (1, 2), but I still find myself unable to understand how they are different. To me, they seem interchangeable in large…
AZhao
  • 13,617
  • 7
  • 31
  • 54
840
votes
5 answers

Multiple Indexes vs Multi-Column Indexes

What is the difference between creating one index across multiple columns versus creating multiple indexes, one per column? Are there reasons why one should be used over the other? For example: Create NonClustered Index IX_IndexName On…
GateKiller
  • 74,180
  • 73
  • 171
  • 204
807
votes
10 answers

How to convert index of a pandas dataframe into a column

How to convert an index of a dataframe into a column? For example: gi ptt_loc 0 384444683 593 1 384444684 594 2 384444686 596 to index1 gi ptt_loc 0 0 384444683 593 1 1 …
msakya
  • 9,311
  • 5
  • 23
  • 31
718
votes
6 answers

How to avoid pandas creating an index in a saved csv

I am trying to save a csv to a folder after making some edits to the file. Every time I use pd.to_csv('C:/Path of file.csv') the csv file has a separate column of indexes. I want to avoid printing the index to csv. I tried: pd.read_csv('C:/Path to…
Alexis
  • 8,531
  • 5
  • 19
  • 21
661
votes
3 answers

Differences between INDEX, PRIMARY, UNIQUE, FULLTEXT in MySQL?

What are the differences between PRIMARY, UNIQUE, INDEX and FULLTEXT when creating MySQL tables? How would I use them?
Sam
656
votes
10 answers

How do I access the ith column of a NumPy multidimensional array?

Given: test = np.array([[1, 2], [3, 4], [5, 6]]) test[i] gives the ith row (e.g. [1, 2]). How do I access the ith column? (e.g. [1, 3, 5]). Also, would this be an expensive operation?
lpl
  • 6,609
  • 3
  • 15
  • 6
595
votes
14 answers

How to see indexes for a database or table in MySQL?

How do I see if my database has any indexes on it? How about for a specific table?
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
563
votes
8 answers

Selecting a row of pandas series/dataframe by integer index

I am curious as to why df[2] is not supported, while df.ix[2] and df[2:3] both work. In [26]: df.ix[2] Out[26]: A 1.027680 B 1.514210 C -1.466963 D -0.162339 Name: 2000-01-03 00:00:00 In [27]: df[2:3] Out[27]: A …
user1642513
548
votes
3 answers

How to reset index in a pandas dataframe?

I have a dataframe from which I remove some rows. As a result, I get a dataframe in which index is something like that: [1,5,6,10,11] and I would like to reset it to [0,1,2,3,4]. How can I do it? The following seems to work: df =…
Roman
  • 124,451
  • 167
  • 349
  • 456
1
2 3
99 100