Here I have a dataframe and an array, please be aware that this dataframe has only 1 column, "ds" and "code" are indices. My purpose is to get rid of all the stocks in this datafram that are not included in the array. The provided link actually does not help Suppose this dataframe names df
dividendyield
ds code
20200601 000001.SZ 1.64
000002.SZ 3.96
000004.SZ 0.00
000005.SZ 0.00
000006.SZ 3.68
... ...
688516.SH 0.00
688566.SH 0.00
688588.SH 0.40
688598.SH 0.00
[3837 rows x 1 columns]
And I have an array like this, which consists of 2000 stock codes, suppose this array names "stk_code"
['000001.SZ' '000002.SZ' '000004.SZ' ... '603992.SH' '603993.SH'
'603997.SH']
When I use
df = df.reindex(stk_code)
It returns
TypeError: Expected tuple, got str
Can anyone helps me with this error, thanks a lot!