我用Pandas创建了一个3列的DataFrame,而我只是试图访问特定行的内容(里面有一个字符串)。
In [1]: from subprocess import check_output, STDOUT
In [2]: print check_output(["snmpwalk", "-V"], stderr=STDOUT, shell=True)
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-2-9886fda8a591> in <module>()
----> 1 print check_output(["snmpwalk", "-V"], stderr=STDOUT, shell=True)
/usr/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
571 if cmd is None:
572 cmd = popenargs[0]
--> 573 raise CalledProcessError(retcode, cmd, output=output)
574 return output
575
CalledProcessError: Command '['snmpwalk', '-V']' returned non-zero exit status 1
In [3]: print check_output(["/usr/bin/snmpwalk", "-V"], stderr=STDOUT, shell=True)
---------------------------------------------------------------------------
CalledProcessError Traceback (most recent call last)
<ipython-input-3-25c11cea9013> in <module>()
----> 1 print check_output(["/usr/bin/snmpwalk", "-V"], stderr=STDOUT, shell=True)
/usr/lib/python2.7/subprocess.pyc in check_output(*popenargs, **kwargs)
571 if cmd is None:
572 cmd = popenargs[0]
--> 573 raise CalledProcessError(retcode, cmd, output=output)
574 return output
575
CalledProcessError: Command '['/usr/bin/snmpwalk', '-V']' returned non-zero exit status 1
我认为tweets = pd.DataFrame()
tweets['text'] = map(lambda tweet: tweet['text'], tweets_data)
tweets['lang'] = map(lambda tweet: tweet['lang'], tweets_data)
tweets['country'] = map(lambda tweet: tweet['place']['country'] if tweet['place'] != None else None, tweets_data)
或tweets['text',0]
可行,但情况并非如此
答案 0 :(得分:0)
如果您正在寻找特定的刺痛,可以使用str.contains
。它的工作原理如下:
获取数据
SELECT TOP(1) [Symbol],[TargetPosition]
FROM [FX].[dbo].[Orders]
GROUP BY [Symbol]
ORDER BY [OrderUTC]
使用import pandas as pd
from io import StringIO
data = """
id tweet
12 "this is the first tweet"
34 "this is the second tweet"
48 "this is the third tweet"
59 "finally the fourth tweet"
"""
df = pd.read_csv(StringIO(data), delimiter='\s+')
str.contains
这将导致:
first = df['tweet'].str.contains('first')
this = df['tweet'].str.contains('this')
fin = df['tweet'].str.contains('finally')