Course Name: Python for Trading: Basic, Section No: 5, Unit No: 15, Unit type: Notebook
infy_close = infy[['Date', 'Close Price']]
we are taking just date and close price but why we need two square bracket it won't working without two square bracket
Hi Sridhar,
The main DataFrame here is infy. To get a single column, you can write infy['Date'], but to get multiple columns, you need to provide a list of column heads. So the list of column heads which you want is ['Date', 'Close Price']. And that goes inside infy[<list_of_columns>]. So here you see double square brackets.
Hope this helps!
Hi Sridhar,
" two square bracket " you mentioned is syntax to get subset of dataframe. Subset of dataframe is selection of specific columns from all available columns in dataframe.
In "infy" dataframe, there might be other columns as well like 'Open Price', 'High Price' etc, but here you want only 'Date' and 'Close Price' so you selected "subset" by using two square bracket.