I read tons of posts from our database for the last few days. with my limited skills in python and pandas and numpy, i am not sure if i found the answers that I desire. so would you please take a look at my situation, and see what i can do with it. and I am sorry about the chinese characters in the searching results.
I am currently writing some quant analysis for personal use. I retrieved a csv file via tushare-pro, which is a 3825-rows dataframe.
df1 = pd.DataFrame(pd.read_csv(stock_stats_ts.csv))
data1 = np.array(df1.loc[:,:])
returns
[[300826 'N测绘' '建筑工程' ... 41.16 16.85 40171.0]
[2770 '科迪乳业' '乳制品' ... 21.05 4.38 47133.0]
[2503 '搜于特' '服饰' ... 8.6 3.08 65664.0]
...
[2260 '*ST德奥' '家用电器' ... 23.08 3.03 24704.0]
[995 '*ST皇台' '白酒' ... 68.05 -35.24 10275.0]
[939 '*ST凯迪' '新型电力' ... 10.79 -74.92 79373.0]]
and then I narrow it down to things i desire, such as code/name/esp/pb/roe
df2 = df1.loc[:,['code','name','esp','pb','npr']]
data2 = np.array(df1.loc[:,:])
returns
[[300826 'N测绘' 1.08 2.79 16.85]
[2770 '科迪乳业' 0.03 2.13 4.38]
[2503 '搜于特' 0.098 2.17 3.08]
...
[2260 '*ST德奥' 0.034 0.0 3.03]
[995 '*ST皇台' -0.079 0.0 -35.24]
[939 '*ST凯迪' -0.362 0.0 -74.92]]
and I also have a list of stock names which i desire from previous session
df3 = pd.DataFrame(pd.read_csv(candidates.csv))
data3 = np.array(df3.loc[:,['candidates']])
returns
[['维维股份']
['ST正源']
['美克家居']
['*ST金山']
['大有能源']
['好当家']
['贵州茅台']
['通策医疗']
['杭州解百']
['耀皮玻璃']
['梅花生物']
['金牌厨柜']
['继峰股份']
['胜利股份']
['渝 开 发']
['云南白药']
['中原环保']
['兴蓉环境']
['华闻集团']
['粤 水 电']
['濮耐股份']
['*ST东南']
['洪涛股份']
['达实智能']
['千红制药']
['闽发铝业']
['史丹利']
['加加食品']
['张家港行']
['国联水产']]
What i am sure of is that my candidates are in df2[name] columns for sure, and then, with what lines of codes so that I can filter my df2 based on the results i have from df3?
Thanks to chief @Rexhil Regmi and @nimrodm, my question worked perfectly with pd.merge. However, all those chinese characters in are encoding in 'gbk' which is unreadable with MS Excel. Any hints to change them into 'utf8'?