简体   繁体   English

向量化DataFrame Python熊猫?

[英]Vectorized DataFrame Python-pandas?

I'm trying to figure out how to print a row given a known entry in a column within my data frame much like this question. 我试图弄清楚如何在给定数据框内某列中的已知条目的情况下打印行,就像这个问题一样。 However, this wasn't working for my DataFrame. 但是,这不适用于我的DataFrame。

In [10]: df
Out[10:
   A   B   C   D
0  a   b   c   d
1  t   f   h   e
2  j   r   y   k

In [11]: df[df['A'].str.contains('t')]

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-11-618e00d5bb36> in <module>()
----> 1 df[df['A'].str.contains('t')]

AttributeError: 'Series' object has no attribute 'str'

Just to try and clarify my goal, say I know 't' is in my DataFrame somewhere and I also know it resides within column A, is there a search option that will print out the entire row it is located within? 只是为了阐明我的目标,比如说我知道“ t”位于我的DataFrame中的某个地方,而且我也知道它位于列A中,是否有一个搜索选项可以打印出它所在的整行?

Why am I getting this error? 为什么会出现此错误?

Vectorized string methods were introduced in pandas 0.9 (so it isn't available as a Series method in version you're using: 0.8). 向量化字符串方法在pandas 0.9引入的 (因此,在您使用的版本中,它不能作为Series方法使用:0.8)。 Refresh your pandas to the latest stable version for the latest and greatest features. 将您的熊猫刷新到最新的稳定版本 ,以获取最新和最强大的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM