Solutions for Week 10 Pandas FDS

Sorted in alphabetical order of month.Seems to be default.To get sorted by date…got to use sort_index

1 Like

Hi, I am also getting the same result despite being Sunday is a non working day for the stock market then how the mean can be computed for the 6th weekday ?

Can anyone help ?


Stock market was operating for 1 hr on October 27th, 2019.

1 Like

For problem 6 (#On the days in which NIFTY50 closed higher than the open, what was the mean of(close-open)for NIFTYNext50), this is what i have done. can anyone confirm if this is correct? i am getting mean as 118.70188679245271

def difference(x):
if ((x.NIFTY50.Close - x.NIFTY50.Open) > 0):
return True
return False

df5[‘NIFTY50’,‘Diff’] = df5.apply(difference, axis=1)
df5[‘NIFTYNEXT50’,‘Diff1’] = (df5.NIFTYNEXT50.Close) - (df5.NIFTYNEXT50.Open)
df5 = df5.sort_index(axis=1)
df_5 = df5[(df5.NIFTY50.Diff) == True]

Looks good to me :+1:
This is how I attempted it:

1 Like


#In 2019, on how many days did the day’s close exceed the 30 day moving average in NIFTY50(exclude first month) and i am getting answer as follows. can someone confirm if this is correct?

df2[‘MA’]= df2[‘Close’].rolling(window=30).mean()
df2[‘Close_MA’] = df2[‘Close’] > df2[‘MA’]

False 160
True 85
Name: Close_MA, dtype: int64

There are several post above you can refer for solution to 8.

My soln: Solutions for Week 10 Pandas FDS

1 Like


Refer to my notebook on GitHub for solution of final problem and please contribute with better code or any error correction if noticed.

GitHub Link :

Unable to find the GitHub page

Sahil Bansal Python Practice | Github

1 Like