[英]Subset of a dataframe in pandas
您可能想要做的是:
monthstest[monthstest["Months"].str.contains("18-")]
從你的行:
monthstest[monthstest.str.contains('-18')]
# the monthstest inside [] is the entire dataframe, which contains fields other than 'Months', so comparing '-18' against one row of record is not well-defined.
因此,您可以嘗試僅考慮“月份”列:
monthstest[monthstest['Month'.str.contains('18-')]] # i think it is '18-'?
另一種方法(不知道它是否更有效):
monthstest[ ['18-' in m for m in monthstest['Month']] ]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.