Python 仅打印频率大于2的字符串
在下面的代码中,我希望pd.plot()忽略所有发生1次的情况。i、 例如,仅多次打印列表中的字符串。我该怎么做呢 下面是一些示例代码Python 仅打印频率大于2的字符串,python,pandas,plot,Python,Pandas,Plot,在下面的代码中,我希望pd.plot()忽略所有发生1次的情况。i、 例如,仅多次打印列表中的字符串。我该怎么做呢 下面是一些示例代码 import pandas as pd import matplotlib.pyplot as plt x = ['a', 'a', 'b', 'c', 'c', 'c', 'c', 'd', 'e', 'e', 'a', 'e', 'e'] pd.Series(x).value_counts().plot('barh') plt.show() 换句话说,“
import pandas as pd
import matplotlib.pyplot as plt
x = ['a', 'a', 'b', 'c', 'c', 'c', 'c', 'd', 'e', 'e', 'a', 'e', 'e']
pd.Series(x).value_counts().plot('barh')
plt.show()
换句话说,“b”和“d”各出现一次。如何在打印前从绘图中删除这些数据点,即不使用xlim=[2,4]
。我正试图用类似的方法来处理我的财务数据。我正在读取一个包含大量行的csv文件,因此我希望在打印之前删除字符串的所有单个实例。如果我需要澄清,请告诉我。
使用:
或者,如果需要单线解决方案:
pd.Series(x).value_counts().loc[lambda x: x > 1].plot('barh')
使用:
或者,如果需要单线解决方案:
pd.Series(x).value_counts().loc[lambda x: x > 1].plot('barh')