Python - Get column name
Dataframe I have Dataframe called "returns" that have time series (index) of returns for 10 sectors. How can I use for loops going through daily time series and find the name of sectors (column) that returns positive? I've tried this below, and was able to get positive returns, but what I need is the names of sectors.
for n in range(0,len(returns))
pos_return = returns.iloc[n][returns.iloc[n]>0]
Here is what my data looks like.
Solution 1:
you can use pos_return = returns.iloc[n][returns.iloc[n]>0].index
which will return an Index object which can be cast to a list or whatever.