Questions tagged [reindex]

459 questions
159
votes
6 answers

How to re-index all subarray elements of a multidimensional array?

The question is how to reset key e.g. for an array: Array ( [1_Name] => Array ( [1] => leo [4] => NULL ) [1_Phone] => Array ( [1] => 12345 [4] => 434324 ) ) reset to : Array ( [1_Name]…
Leo Chan
  • 4,217
  • 8
  • 31
  • 47
154
votes
4 answers

After array_filter(), how can I reset the keys to go in numerical order starting at 0

I just used array_filter to remove entries that had only the value '' from an array, and now I want to apply certain transformations on it depending on the placeholder starting from 0, but unfortunately it still retains the original index. I looked…
jel402
  • 1,543
  • 2
  • 9
  • 4
52
votes
5 answers

Sort dataframe by string length

I want to sort by name length. There doesn't appear to be a key parameter for sort_values so I'm not sure how to accomplish this. Here is a test df: import pandas as pd df = pd.DataFrame({'name': ['Steve', 'Al', 'Markus', 'Greg'], 'score': [2, 4, 2,…
Alex
  • 12,078
  • 6
  • 64
  • 74
39
votes
5 answers

How to really reindex data in elasticsearch

I have added new mappings (mainly not_analyzed versions of existing fields) I now have to figure out how to reindex the existing data. I have tried following the guide on elastic search website but that is just too confusing. I have also tried using…
metase
  • 1,169
  • 2
  • 16
  • 29
30
votes
5 answers

Create multiindex from existing dataframe

I've spent hours browsing everywhere now to try to create a multiindex from dataframe in pandas. This is the dataframe I have (posting excel sheet mockup. I do have this in pandas dataframe): And this is what I want: I have tried newmulti =…
puifais
  • 738
  • 2
  • 9
  • 20
22
votes
2 answers

Pandas reindex dates in Groupby

I have a dataframe with sporadic dates as the index, and columns = 'id' and 'num'. I would like to pd.groupby the 'id' column, and apply the reindex to each group in the dataframe. My sample dataset looks like this: id num 2015-08-01 …
clg4
  • 2,863
  • 6
  • 27
  • 32
19
votes
3 answers

Difference between df.reindex() and df.set_index() methods in pandas

I was confused by this, which is very simple but I didn't immediately find the answer on StackOverflow: df.set_index('xcol') makes the column 'xcol' become the index (when it is a column of df). df.reindex(myList), however, takes indexes from…
Ricardo Guerreiro
  • 497
  • 1
  • 4
  • 17
17
votes
2 answers

Why doesn't pandas reindex() operate in-place?

From the reindex docs: Conform DataFrame to new index with optional filling logic, placing NA/NaN in locations having no value in the previous index. A new object is produced unless the new index is equivalent to the current one and…
Luis
  • 3,327
  • 6
  • 35
  • 62
17
votes
1 answer

Reindexing a specific level of a MultiIndex dataframe

I have a DataFrame with two indices and would like to reindex it by one of the indices. from pandas_datareader import data import matplotlib.pyplot as plt import pandas as pd # Instruments to download tickers = ['AAPL'] # Online source one should…
Bruno
  • 1,329
  • 2
  • 15
  • 35
17
votes
2 answers

Pandas: Reindex Unsorts Dataframe

I'm having some trouble sorting and then resetting my Index in Pandas: dfm = dfm.sort(['delt'],ascending=False) dfm = dfm.reindex(index=range(1,len(dfm))) The dataframe returns unsorted after I reindex. My ultimate goal is to have a sorted…
David Yang
  • 2,101
  • 13
  • 28
  • 46
16
votes
4 answers

ALTER INDEX failed because of QUOTED_IDENTIFIER when running from sp_msForEachTable

When I try to rebuild an index on a table: ALTER INDEX ALL ON [dbo].[Allocations] REBUILD that works fine. But when I call EXECUTE sp_msForEachTable 'ALTER INDEX ALL ON ? REBUILD' I reach the same same table, and it fails with: Msg 1934, Level…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
16
votes
1 answer

pandas reindex DataFrame with datetime objects

Is it possible to reindex a pandas DataFrame using a column made up of datetime objects? I have a DataFrame df with the following columns: Int64Index: 19610 entries, 0 to 19609 Data columns: cntr 19610 non-null values #int datflt …
BFTM
  • 3,225
  • 6
  • 23
  • 22
15
votes
5 answers

MAGENTO: Reindexing price programmatically

I update prices in magento programmatically. How can I reindexing prices after this update. Now I used SSH command: php indexer.php --reindex catalog_product_price
dido
  • 2,330
  • 8
  • 37
  • 54
13
votes
1 answer

Is there a way to prevent dtype from changing from Int64 to float64 when reindexing/upsampling a time-series?

I am using pandas 0.17.0 and have a df similar to this one: df.head() Out[339]: A B C DATE_TIME 2016-10-08 13:57:00 in 5.61 1 2016-10-08 14:02:00 in 8.05 1 2016-10-08 14:07:00 in 7.92 …
vera
  • 297
  • 3
  • 11
12
votes
1 answer

Change type and reindex in Elasticsearch

I recently upgraded my ELK stack (logstash 2.3.4 using redis 3.2.3, Elasticsearch 2.3.5 and Kibana 4.5.4) from (logstash 1.4.1/1.4.2 using redis 2.8.24, Elasticsearch 1.2.2 and Kibana 3.1.1). The upgrade went well but after the upgrade I had some…
Mike
  • 121
  • 1
  • 6
1
2 3
30 31