小编Use*_*898的帖子

在Pandas Dataframe列中填写缺少的日期值

我正在使用Pandas使用数据框存储股票价格数据.数据集中有2940行.数据集快照显示如下:

在此输入图像描述

时间序列数据不包含星期六和星期日的值.因此必须填补缺失值.
这是我写的代码,但它没有解决问题:

import pandas as pd
import numpy as np
import os
os.chdir('C:/Users/Admin/Analytics/stock-prices')

data  = pd.read_csv('stock-data.csv')

# PriceDate Column - Does not contain Saturday and Sunday stock entries
data['PriceDate'] =  pd.to_datetime(data['PriceDate'], format='%m/%d/%Y')
data = data.sort_index(by=['PriceDate'], ascending=[True])


# Starting date is Aug 25 2004
idx = pd.date_range('08-25-2004',periods=2940,freq='D')


data = data.set_index(idx)
data['newdate']=data.index
newdate=data['newdate'].values   # Create a time series column   


data = pd.merge(newdate, data, on='PriceDate', how='outer')
Run Code Online (Sandbox Code Playgroud)

如何填写周六和周日的缺失值?

python numpy time-series pandas

7
推荐指数
1
解决办法
6684
查看次数

Python:使用Statsmodels - 线性回归预测y值

我正在使用Python的statsmodels库来使用线性回归来预测未来的平衡.csv文件显示如下:

| 平衡
3 | 30
8 | 57
9 | 64
13 | 72
3 | 36
6 | 43
11 | 59
21 | 90
1 | 20
16 | 83
它包含"年份"作为独立变量"x",而"余额"是从属"y"的可变

以下是此数据的线性回归代码:

import pandas as pd
import statsmodels.api as sm
from statsmodels.formula.api import ols
import numpy as np
from matplotlib import pyplot as plt

import os
os.chdir('C:\Users\Admin\Desktop\csv')

cw = pd.read_csv('data-table.csv')
y=cw.Balance
X=cw.Year

X = sm.add_constant(X)  # Adds a constant term to the predictor

est = sm.OLS(y, …
Run Code Online (Sandbox Code Playgroud)

python regression pandas statsmodels

5
推荐指数
1
解决办法
2650
查看次数

如何实现泊松回归?

有两种类型的广义线性模型:
1.对数线性回归,也称为泊松回归
2. Logistic回归

如何在Python中实现价格弹性预测的泊松回归?

python statistics regression

4
推荐指数
2
解决办法
1万
查看次数

如何在Windows上安装opencv_contrib存储库?

我想使用基于FLANN的匹配器进行功能匹配.为此,需要SIFT算法.在Linux中,可以使用'cmake'和'make'命令.

但是如何在Windows 上安装opencv_contrib

python windows sift opencv3.0

3
推荐指数
1
解决办法
4934
查看次数

为什么predict_proba函数以相反的顺序打印概率?

我正在使用scikit-learn使用Logistic回归实现分类。使用predict()功能预测类别标签,而使用predict_proba()功能打印预测概率。

代码段粘贴在下面:

# Partition the dataset into train and test data
X_train, X_test, y_train, y_test = train_test_split(ds_X, ds_y, test_size=0.33, random_state=42) 

y_pred = logreg.predict(X_test)                             # Predicted class labels from test features
y_predicted_proba = logreg.predict_proba(X_test)            # Predicted probabilities from test features
Run Code Online (Sandbox Code Playgroud)


预测的标签被打印为

array([1, 1, 1, 1, 1, 1, 1, 1, 0, 1.......... and so on
Run Code Online (Sandbox Code Playgroud)

相应的预测概率打印为

array([[ 0.03667012,  0.96332988],
       [ 0.03638475,  0.96361525],
       [ 0.03809274,  0.96190726],
       [ 0.01746768,  0.98253232],
       [ 0.02742639,  0.97257361],
       [ …
Run Code Online (Sandbox Code Playgroud)

python machine-learning scikit-learn logistic-regression

3
推荐指数
1
解决办法
4929
查看次数

在循环中获取“检查flume.conf 的更改”

我正在使用 Apache Flume 1.4.0 来收集日志文件 (auth.log) 并存储在 HDFS (Hadoop 2.6.0) 中。使用的命令是:

 bin/flume-ng agent --conf ./conf/ -f flume.conf -Dflume.root.logger=DEBUG,console -n agent
Run Code Online (Sandbox Code Playgroud)

flume.conf文件包含以下内容:

agent.channels.memory-channel.type = memory

agent.sources.tail-source.type = exec
agent.sources.tail-source.command = tail -F /var/log/auth.log
agent.sources.tail-source.channels = memory-channel

agent.sinks.log-sink.channel = memory-channel
agent.sinks.log-sink.type = logger
agent.sinks.hdfs-sink.channel = memory-channel
agent.sinks.hdfs-sink.type = hdfs
agent.sinks.hdfs-sink.hdfs.path = hdfs://localhost:54310/usr/auth.log
agent.sinks.hdfs-sink.hdfs.fileType = DataStream

agent.channels = memory-channel
agent.sources = tail-source
agent.sinks = log-sink hdfs-sink
Run Code Online (Sandbox Code Playgroud)

命令运行后,以下消息不断循环重复:

(conf-file-poller-0) [DEBUG - org.apache.flume.node.PollingPropertiesFileConfigurationProvider$FileWatcherRunnable.run(PollingPropertiesFileConfigurationProvider.java:126)] Checking file:flume.conf for changes
Run Code Online (Sandbox Code Playgroud)

可能是什么原因 ?

ubuntu hadoop flume flume-ng

2
推荐指数
1
解决办法
1357
查看次数

如何将Python与Qlikview连接以进行数据可视化?

我正在使用Scikit-Learn和Pandas Python数据分析库.如何使用Qlikview等数据可视化工具来连接Python?

python qlikview tableau-api scikit-learn

2
推荐指数
1
解决办法
5809
查看次数

PL / SQL:ORA-00932:数据类型不一致:预期的UDT得到了NUMBER

我正在执行PL / SQL代码以显示“失败预留”表中的“货币代码”。使用对象类型和嵌套表集合。
运行PL / SQL代码时,将产生以下错误。相应的行在PL / SQL代码部分中突出显示。

错误报告:

ORA-06550: line 27, column 11:
PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got NUMBER
ORA-06550: line 27, column 4:
PL/SQL: SQL Statement ignored
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:
Run Code Online (Sandbox Code Playgroud)


该代码粘贴在下面:

DDL-表创建:

CREATE TABLE FAILEDRESERVATION
(   
    FAILEDRESERVATIONID NUMBER(18,0), 
    FK_TRANSACTIONID NUMBER(18,0), 
    DEBITRESERVATIONID NUMBER(18,0), 
    RESERVATIONTIME DATE, 
    RESERVATIONAMOUNT NUMBER(18,5), 
    CURRENCYCODE CHAR(3 BYTE), 
    AVAILABLEAMOUNT NUMBER(18,5)
);

ALTER TABLE FAILEDRESERVATION 
ADD CONSTRAINT "PK_FAILEDRESERVATION" PRIMARY KEY ("FAILEDRESERVATIONID");
Run Code Online (Sandbox Code Playgroud)


对象类型:

CREATE OR REPLACE …
Run Code Online (Sandbox Code Playgroud)

oracle plsql

0
推荐指数
1
解决办法
2万
查看次数

如何在 Python 中使用正则表达式动态匹配整个单词

使用正则表达式,我想完全在 Python 中匹配一系列单词。静态是可能的,但我不知道动态匹配方式。

静态方法

import re
print(re.search(r'\bsmaller than or equal\b', 'When the loan amount is smaller than or equal to 50000'))
Run Code Online (Sandbox Code Playgroud)

我试图通过将整个序列与列表匹配来动态地做同样的事情。
这是下面的代码片段:

import re
list_less_than_or_equal = ['less than or equal', 'lesser than or equal', 'lower than or equal', 'smaller than or equal','less than or equals', 'lesser than or equals', 'lower than or equals', 'smaller than or equals', 'less than equal', 'lesser than equal', 'higher than equal','less than equals', 'lesser than equals', 'higher than equals']

for word in list_less_than_or_equal:
    print(re.search(r'\b'+word+'\b', …
Run Code Online (Sandbox Code Playgroud)

python regex string-matching

0
推荐指数
1
解决办法
1275
查看次数