我的初始数据框df:
discharge1 discharge2
datetime
2018-04-25 18:37:00 5862 4427
2018-04-25 21:36:30 6421 4581
2018-04-25 22:13:00 5948 4779
2018-04-26 00:11:30 5703 4314
2018-04-26 02:27:00 4988 3868
2018-04-26 04:28:30 4812 3823
2018-04-26 06:22:30 4347 3672
2018-04-26 10:50:30 3896 3546
2018-04-26 12:04:30 3478 3557
2018-04-26 14:02:30 3625 3598
2018-04-26 15:31:30 3751 3606
Run Code Online (Sandbox Code Playgroud)
我想要做的是让我的日期成为列表、数组或系列,我可以在其中迭代列表中的所有元素。这样我就可以使用这些日期来访问另一个数据框中的行df_other,最后将它们附加到一个新的数据框中df_new:
for date in date_list():
df_new = df_new.append(df_other.iloc[df_other.index.get_loc(date)])
Run Code Online (Sandbox Code Playgroud)
对于我列表中的日期应该运行为:
df_new.append(df_other.iloc[df_other.index.get_loc('2018-04-25 18:37:00')])
Run Code Online (Sandbox Code Playgroud)
我尝试使用df.index但返回一个列表Datetimeindex,我只能访问每个日期:
display(df.index[0])
Timestamp('2018-04-25 18:37:00')
Run Code Online (Sandbox Code Playgroud)
时间戳部分破坏了我的.append通话。
也尝试过df.index.tolist(),但会返回以下列表:[Timestamp('2018-04-25 …
代码如下:
import spacy
from nltk import Tree
en_nlp = spacy.load('en')
parsed = en_nlp(u"Photos under low lighting are poor, both front and back cameras.")
print(u'sentence:{0}'.format(parsed.text))
try2 = []
print(u'parsed_sentence_children::{0}'.format([(x.text,x.pos_,x.dep_,[(x.text,x.dep_) for x in list(x.children)]) for x in parsed]))
print("\n\n")
for x in parsed:
if x.pos_=="NOUN" and x.dep_=="nsubj":
print(u'Noun and noun subject:{0}'.format(try2 =[(x.text,x.pos_,x.dep_,[(x.text,x.pos_)for x in list(x.ancestors)])])
Run Code Online (Sandbox Code Playgroud)
其输出是:
[(u'Photos', u'NOUN', u'nsubj', [(u'are', u'VERB')]
现在我希望打印acomp以下子项:
[(u'are', u'VERB')]
这是以下项的祖先:
[(u'Photos', u'NOUN', u'nsubj')]
我怎样才能做到这一点?
我想用数组中给定的标量划分稀疏矩阵的行。
例如,我有一个csr_matrix C:
C = [[2,4,6], [5,10,15]]
D = [2,5]
Run Code Online (Sandbox Code Playgroud)
我希望C除法后的结果是:
result = [[1, 2, 3], [1, 2, 3]]
Run Code Online (Sandbox Code Playgroud)
我已经使用我们用于numpy数组的方法尝试了这个:
result = C / D[:,None]
Run Code Online (Sandbox Code Playgroud)
但这似乎真的很慢。如何在稀疏矩阵中有效地做到这一点?
我写了一个如下所示的类:
class Logger:
@staticmethod
def get_timestamp():
import datetime
return datetime.datetime.utcnow()
def print_log(self,color, write_level, msg):
return color
def log_level_print(self,log_level, write_level, msg):
if log_level == 'ERROR':
return print_log(bcolors.FAIL, write_level, msg)
if log_level == 'WARN':
return print_log(bcolors.WARNING, write_level, msg)
if log_level == 'INFO':
return print_log(bcolors.OKGREEN, write_level, msg)
if log_level == 'DEBUG':
return print_log(bcolors.OKBLUE, write_level, msg)
else:
print(f"{Logger.get_timestamp()} {bcolors.FAIL}: Invalid LOG type{bcolors.ENDC}")
return
Run Code Online (Sandbox Code Playgroud)
在这里,我正在使用这个类:
from logger import Logger
demo = Logger()
print(demo.log_level_print('ERROR','ssdsd','sdsdsd'))
Run Code Online (Sandbox Code Playgroud)
我无法调用此函数,出现错误:
NameError: name 'print_log' is not defined
我有一个 pandas dataframe,我正在调用一个函数来在不满足条件的列中填充 NaN 。
以下是我的代码:
def clean_feedback(DF):
feed_id = DF.id_y.unique()
for ID in feed_id:
Min = np.argmin(np.abs(DF[DF.id_y == ID].created_at_x - DF[DF.id_y == ID].created_at_y))
print(Min)
DF[DF.id_y == ID].loc[DF[DF.id_y == ID].index != Min, 'comments'] = np.nan
return DF[DF.id_y == ID]
Run Code Online (Sandbox Code Playgroud)
示例数据框是:
id_x user_id merchant_id amount_spent bill_number created_at_x checked_in chain_id id_y feedback_setting_id comments created_at_y updated_at feedback_type
1097 268868 975 42 149 None 2016-12-14 12:11:14 1 NaN 219 194 Lovely cafe! 2017-03-22 12:55:05 2017-10-05 06:45:49 1
2150 468876 975 42 278 None …Run Code Online (Sandbox Code Playgroud) 我想用它spacy从文本中取出句子。
nlp = English() # just the language with no model
sentencizer = nlp.create_pipe("sentencizer")
nlp.add_pipe(sentencizer)
doc = nlp("This is a sentence. This is another sentence.")
for sent in doc.sents:
print(sent.text)
Run Code Online (Sandbox Code Playgroud)
是否有可能提高句子分割器绕过规则的可靠性,例如从不在像“no.”这样的首字母缩略词之后分割句子。
当然,想象一下我有一堆非常技术性和特殊的缩写词。
你将如何进行?
假设在这个例子中,如何config.json在conftest使用pytest.
$ pwd
/home/user/repo/main
$ pytest testcases/project_(1/2)/test_suite_(1/2).py
Run Code Online (Sandbox Code Playgroud)
目录结构:
??? main
? ??? conftest.py # conftest file for my fixtures
? ??? testcases
? ??? project_1
? ? (contains these files -- test_suite_1.py, config.json)
? ??? project_2
? (contains these files -- test_suite_2.py, config.json)
??? workflows
? ??? libs
Run Code Online (Sandbox Code Playgroud) 我在设计 a 时遇到一些问题QListWidget。我一直在寻找如何将样式设置为 aScrollBar内的 a QListWidget,但我找不到答案。