我正在使用 python 获取 5 分钟前的时间。
代码:
import datetime
import time
now = datetime.datetime.now()
current_time = now.strftime(f"%Y-%m-%d %H:%M")
print(current_time)
2020-07-27 08:35:00
Run Code Online (Sandbox Code Playgroud)
我的问题是如何获得 5 分钟前的时间。
就像是
current_time-5mins
Run Code Online (Sandbox Code Playgroud) 代码:
from plotly.offline import init_notebook_mode, iplot, iplot_mpl
def plot_train_test(train, test, date_split):
data = [Candlestick(x=train.index, open=train['open'], high=train['high'], low=train['low'], close=train['close'],name='train'),
Candlestick(x=test.index, open=test['open'], high=test['high'], low=test['low'], close=test['close'],name='test')
]
layout = {
'shapes': [
{'x0': date_split, 'x1': date_split, 'y0': 0, 'y1': 1, 'xref': 'x', 'yref': 'paper',
'line': {'color': 'rgb(0,0,0)', 'width': 1}}],
'annotations': [{'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'left','text': ' test data'},
{'x': date_split, 'y': 1.0, 'xref': 'x', 'yref': 'paper', 'showarrow': False, 'xanchor': 'right', 'text': 'train data '}] }
figure …Run Code Online (Sandbox Code Playgroud) 在Vue.js中:
默认情况下,v-model在每个输入事件之后将输入与数据同步(除了如上所述的IME组成)。您可以添加lazy修饰符以在更改事件后进行同步:
<!-- synced after "change" instead of "input" -->
<input v-model.lazy="msg" >
Run Code Online (Sandbox Code Playgroud)
react有类似的修饰符或功能吗?在官方文档的哪一部分?
我的 Django 网站使用 Nginx 托管在 digitalocean ubuntu 16.04 中。
我已经在这里设置了 digitalocean CORS 配置https://www.digitalocean.com/docs/spaces/how-to/cors/我在“来源”中添加了我的域名,检查了“允许的方法”中的所有选项,我唯一没有做的就是在“Alowed Headers”中添加标题,因为我不知道要添加什么。
当我使用 digitalocean Spaces(一种基于并与 Amazon S3 非常相似的服务)作为我的静态和媒体文件存储时。请求的资源错误中不存在“Access-Control-Allow-Origin”标头:
CORS 政策已阻止从来源“ https://kjmg.co ”访问“ https://nyc3.digitaloceanspaces.com/kjmgstorage/kjmgstorage/fonts/fontawesome-webfont.woff2?v=4.7.0 ”上的字体:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问Origin ' https://kjmg.co '。
我尝试使用 django-cors-headers,但我收到:
502 错误网关 nginx/1.10.3 (Ubuntu)
所以只好卸载了。
有朋友知道吗?非常感谢!
我已经训练了一个 LSTM 网络来预测股票价格。但我不知道如何保存和恢复它。
以下是我的代码:
CONST_TRAINING_SEQUENCE_LENGTH = 12
CONST_TESTING_CASES = 5
def dataNormalization(data):
return [(datum - data[0]) / data[0] for datum in data]
def dataDeNormalization(data, base):
return [(datum + 1) * base for datum in data]
def getDeepLearningData(ticker):
# Step 1. Load data
data = pandas.read_csv('./data/Intraday/' + ticker + '.csv')[
'close'].tolist()
# Step 2. Building Training data
dataTraining = []
for i in range(len(data) - CONST_TESTING_CASES * CONST_TRAINING_SEQUENCE_LENGTH):
dataSegment = data[i:i + CONST_TRAINING_SEQUENCE_LENGTH + 1]
dataTraining.append(dataNormalization(dataSegment))
dataTraining = numpy.array(dataTraining)
numpy.random.shuffle(dataTraining)
X_Training …Run Code Online (Sandbox Code Playgroud) 我正在合并 2 个 dfs,df1 和 df2,虽然不匹配,但结果将为 Nan,但我需要它默认为 0。
df1 = pd.merge(df1, df2, left_on='MortTab', right_on='MortTab', how='left',suffixes=(' ', ''))
Run Code Online (Sandbox Code Playgroud)
现在我用这种方式将Nan转换为0:
for i in ['col1','col2','col3']: #columns that I want to check the values are NaN or not
df1[i] = np.where(df1[i].isnull(), 0, df_ia[i]) #if it's NaN, convert it to 0,or keep the same
Run Code Online (Sandbox Code Playgroud)
我手动循环每个列值来检查,如果该值是 NaN ,如果是,将其转换为 0 ,如果否保持不变。
有更好的方法吗?
代码:
df['Rep'] = df['Rep'].str.replace('\\n', ' ')
Run Code Online (Sandbox Code Playgroud)
问题:如果 df['Rep'] 为空或 null ,则会出现错误:
Failed: Can only use .str accessor with string values!
Run Code Online (Sandbox Code Playgroud)
无论如何可以处理列值为空或为空时的情况吗?如果为空或 null ,则忽略该行
我有一个这样的数据结构:
[ {'SNAPSHOT': {'SnapshotVersion': '304'}},
{'SNAPSHOT': {'SnapshotCreationDate': '2015-06-21 17:33:41'}},
{'CafeData': {'CafeVersion': '2807'}},
{'CafeData': {'IsSoftwareOnly': '1'}},
{'CafeData'{'IsPassportTCPIP': '1'}}
Run Code Online (Sandbox Code Playgroud)
]
输出应该是这样的:
[ {'SNAPSHOT': {'SnapshotVersion': '304','SnapshotCreationDate': '2015-06-21 17:33:41'}},
{'CafeData': {'CafeVersion': '2807','IsSoftwareOnly': '1','IsPassportTCPIP': '1'}}
]
Run Code Online (Sandbox Code Playgroud) 我在 python 中使用 selenium,现在我想通过元素 id 名称的一部分来定位元素,我该怎么办?
例如,现在我已经通过 id 名称coption5找到了一个项目:
sixth_item = driver.find_element_by_id("coption5")
Run Code Online (Sandbox Code Playgroud)
无论如何我只能通过使用coption来定位这个元素吗?
我有一个表 my_table:
case_id first_created last_paid submitted_time
3456 2021-01-27 2021-01-29 2021-01-26 21:34:36.566023+00:00
7891 2021-08-02 2021-09-16 2022-10-26 19:49:14.135585+00:00
1245 2021-09-13 None 2022-10-31 02:03:59.620348+00:00
9073 None None 2021-09-12 10:25:30.845687+00:00
6891 2021-08-03 2021-09-17 None
Run Code Online (Sandbox Code Playgroud)
我创建了 2 个新变量:
case_id first_created last_paid submitted_time
3456 2021-01-27 2021-01-29 2021-01-26 21:34:36.566023+00:00
7891 2021-08-02 2021-09-16 2022-10-26 19:49:14.135585+00:00
1245 2021-09-13 None 2022-10-31 02:03:59.620348+00:00
9073 None None 2021-09-12 10:25:30.845687+00:00
6891 2021-08-03 2021-09-17 None
Run Code Online (Sandbox Code Playgroud)
输出:
case_id first_created last_paid submitted_time create_duration paid_duration
3456 2021-01-27 2021-01-29 2021-01-26 21:34:36.566023+00:00 1 3
7891 2021-08-02 2021-09-16 2022-10-26 19:49:14.135585+00:00 …Run Code Online (Sandbox Code Playgroud) python ×6
dataframe ×2
pandas ×2
date ×1
datetime ×1
dictionary ×1
django ×1
keras ×1
list ×1
lstm ×1
matplotlib ×1
nginx ×1
numpy ×1
plot ×1
plotly ×1
postgresql ×1
prediction ×1
python-3.x ×1
reactjs ×1
selenium ×1
tensorflow ×1
time ×1
vue.js ×1
xpath ×1