<p>对所有匹配值使用<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.extractall.html" rel="nofollow noreferrer">^{<cd1>}</a>,对单词边界使用<code>\b\b</code>:</p>
<pre><code>top = ['GME', 'MVIS', 'TSLA', 'AMC']
pat = '|'.join(r"\b{}\b".format(x) for x in top)
df = discussion.set_index('dt')['text'].str.extractall('('+pat+')')[0].reset_index(name='v')
print (df)
dt match v
0 2021-03-19 20:59:49+06 0 GME
1 2021-05-21 15:56:06+06 0 TSLA
</code></pre>
<p>对于计数使用<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.crosstab.html" rel="nofollow noreferrer">^{<cd3>}</a>:</p>
<pre><code>df1 = pd.crosstab(df['dt'], df['v'])
print (df1)
val GME TSLA
dt
2021-03-19 20:59:49+06 1 0
2021-05-21 15:56:06+06 0 1
</code></pre>
<p>由<a href="http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.plot.html" rel="nofollow noreferrer">^{<cd4>}</a>进行的最后绘图:</p>
<pre><code>df1.plot()
</code></pre>
<p>按<a href="https://stackoverflow.com/questions/29532894/ipython-jupyter-notebook-and-pandas-how-to-plot-multiple-graphs-in-a-for-loop">this</a>解决方案编辑:</p>
<pre><code>import matplotlib.pyplot as plt
for col in df1.columns:
df1[col].plot()
plt.show()
</code></pre>