0

I have the following dataframe:

a = df['Low'].groupby(['week']).min()
week
1     1699
2     1721
3     1741
4     1809
...
28    2592
29    2570
30    2696
31    2683
53    1735
Name: Low, dtype: int32

To get a date in this i use this function:

df[df['Low'].isin([1735])]['Date1']

Date        week  day
2020-12-31  53    31    2020-12-31
Name: Date1, dtype: datetime64[ns]

To get all the dates when these values occured i used a for loop:

for stuff in low:
    df[df['Low'].isin([stuff])]['Date1']

Which produces :

MultiIndex([('2021-01-06', 1, 6)],
           names=['Date', 'week', 'day'])
MultiIndex([('2021-01-15', 2, 15)],
           names=['Date', 'week', 'day'])
MultiIndex([('2021-01-19', 3, 19)],
           names=['Date', 'week', 'day'])
MultiIndex([('2021-01-27', 4, 27)],
           names=['Date', 'week', 'day'])
MultiIndex([('2021-02-01', 5, 1)],
           names=['Date', 'week', 'day'])
MultiIndex([('2021-02-10', 6, 10)],
           names=['Date', 'week', 'day'])
MultiIndex([('2021-02-19', 7, 19)],
           names=['Date', 'week', 'day'])

I there anyway i could just get the dates? The df looks like this:

            High    Low     Open    Close   Volume  Adj Close   Date1   month
Date    week    day                                 
2020-12-31  53  31  1758.930054     1735    1735.420044     1751.880005     1011900     1751.880005     2020-12-31  12
2021-01-04  1   4   1760.650024     1707    1757.540039     1728.239990     1901900     1728.239990     2021-01-04  1
2021-01-05  1   5   1747.670044     1718    1725.000000     1740.920044     1145300     1740.920044     2021-01-05  1
2021-01-06  1   6   1748.000000     1699    1702.630005     1735.290039     2602100     1735.290039     2021-01-06  1
2021-01-07  1   7   1788.400024     1737    1740.060059     1787.250000     2265000     1787.250000     2021-01-07  1
...     ...     ...     ...     ...     ...     ...     ...     ...     ...     ...
2021-08-02  31  2   2720.409912     2693    2709.689941     2719.790039     1007000     2719.790039     2021-08-02  8
2021-08-03  31  3   2726.709961     2683    2720.000000     2725.600098     953200  2725.600098     2021-08-03  8
2021-08-04  31  4   2730.760010     2708    2724.989990     2720.570068     826400  2720.570068     2021-08-04  8
2021-08-05  31  5   2739.000000     2712    2720.570068     2738.800049     593300  2738.800049     2021-08-05  8
2021-08-06  31  6   2741.601074     2720    2725.899902     2740.719971     678000  2740.719971     2021-08-06  8

151 rows × 8 columns
3
  • 1
    Not clear what you want. What is the expected output? Commented Aug 9, 2021 at 6:24
  • I was looking for just the index date or date column value Commented Aug 9, 2021 at 6:27
  • 1
    Kindly share a sample reproducible example. df. To_dict() Commented Aug 9, 2021 at 6:30

1 Answer 1

1

To get a certain value of a multi level index you can simply use:

df.index.get_level_values('Date')

or

df.index.get_level_values(0)

You could apply this to your for loop like this:

for stuff in low:
    df[df['Low'].isin([stuff])]['Date1'].index.get_level_values('Date')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.