0
sns.distplot(returns.ix['2015-01-01':'2015-12-31']['MS Return'],color='green',bins=100)

while running this code I am getting an error so how to replace it with 'iloc' and 'loc' method.

The data head is as below:

BAC Return  C Return    GS Return   JPM Return  MS Return   WFC Return

Date

2017-12-29  NaN NaN NaN NaN NaN NaN
2017-12-28  0.009485    0.009004    0.006830    0.007948    0.003431    0.010384
2017-12-27  -0.002349   -0.002531   -0.002144   -0.005288   -0.001519   -0.005710
zvone
  • 18,045
  • 3
  • 49
  • 77

2 Answers2

0

Just as you did with .ix, start, end - datetime format, not a string

dataframe.loc[start:end]

And check first if dataframe.index returns you datetime instead of integers Otherwise use dataframe.set_index() method

user8075709
  • 115
  • 2
  • 9
0

iloc and loc split the job ix did in two.

Use iloc to address the dataset like a numpy array (eg returns.iloc[10:20,0:5], .head() is equivalent to .iloc[:5]).

Use loc to access a row by index so your code should read:

sns.distplot(returns.loc['2015-01-01':'2015-12-31']['MS Return'],color='green',bins=100)
Paula Thomas
  • 1,152
  • 1
  • 8
  • 13