我有以下DataFrame data
随机索引值:
A B
100 0 7
203 5 4
5992 0 10
2003 9 8
20 10 5
12 6 2
Run Code Online (Sandbox Code Playgroud)
我想添加一个带有行号的新列'C'.例如:
A B C
100 0 7 0
203 5 4 1
5992 0 10 2
2003 9 8 3
20 10 5 4
12 6 2 5
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
我目前正在使用一个基本的 LSTM 来进行回归预测,我想实现一个因果 CNN,因为它应该在计算上更有效。
我正在努力弄清楚如何重塑我当前的数据以适应因果 CNN 单元格并表示相同的数据/时间步长关系以及应该设置的膨胀率。
我当前的数据是这样的:(number of examples, lookback, features)
这是我现在正在使用的 LSTM NN 的一个基本示例。
lookback = 20 # height -- timeseries
n_features = 5 # width -- features at each timestep
# Build an LSTM to perform regression on time series input/output data
model = Sequential()
model.add(LSTM(units=256, return_sequences=True, input_shape=(lookback, n_features)))
model.add(Activation('elu'))
model.add(LSTM(units=256, return_sequences=True))
model.add(Activation('elu'))
model.add(LSTM(units=256))
model.add(Activation('elu'))
model.add(Dense(units=1, activation='linear'))
model.compile(optimizer='adam', loss='mean_squared_error')
model.fit(X_train, y_train,
epochs=50, batch_size=64,
validation_data=(X_val, y_val),
verbose=1, shuffle=True)
prediction = model.predict(X_test)
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个新的 CNN 模型(虽然不是因果关系,因为'causal'
填充只是Conv1D …
我试图将以下列表值输入到下面的url字符串中.当我执行以下操作时:
tickers = ['AAPL','YHOO','TSLA','NVDA']
url = 'http://www.zacks.com/stock/quote/{}'.format(tickers)`
Run Code Online (Sandbox Code Playgroud)
Python返回
http://www.zacks.com/stock/quote/['AAPL', 'YHOO', 'TSLA', 'NVDA']`
Run Code Online (Sandbox Code Playgroud)
我希望它做的是迭代列表并返回以下内容:
http://www.zacks.com/stock/quote/AAPL
http://www.zacks.com/stock/quote/YHOO
http://www.zacks.com/stock/quote/TSLA
http://www.zacks.com/stock/quote/NVDA
Run Code Online (Sandbox Code Playgroud)
谢谢.
我之前问过类似的问题 - pandas - Reorganize a multi-row & multi-column DataFrame into single-row & multi-column DataFrame,但是,当我使用提供的解决方案时:
v = df.unstack().to_frame().sort_index(level=1).T
v.columns = v.columns.map('_'.join)
Run Code Online (Sandbox Code Playgroud)
在以下 DataFrame 上(与上述答案中的示例相比,具有切换的列和行值),
index A B C
1 Apple Orange Grape
2 Car Truck Plane
3 House Apartment Garage
Run Code Online (Sandbox Code Playgroud)
但是,这一行:v.columns = v.columns.map('_'.join)
抛出以下错误:TypeError: sequence item 1: expected str instance, int found
有什么办法可以得到下面的输出吗?
A_1 A_2 A_3 B_1 B_2 B_3 C_1 C_2 C_3
0 Apple Orange Grape Car Truck Plane House Apartment Garage
Run Code Online (Sandbox Code Playgroud)
谢谢。
这个问题是我上一个问题的后续问题:Multi-feature causal CNN-Keras implementation,但是,有很多事情我不清楚,我认为这值得一个新问题。这里有问题的模型是根据上述帖子中接受的答案构建的。
我正在尝试将因果 CNN 模型应用于具有 5 个特征的 10 个序列的多元时间序列数据。
lookback, features = 10, 5
Run Code Online (Sandbox Code Playgroud)
过滤器和内核应该设置为什么?
应该将扩张设置为什么?
lookback
模型的?filters = 32
kernel = 5
dilations = 5
dilation_rates = [2 ** i for i in range(dilations)]
model = Sequential()
model.add(InputLayer(input_shape=(lookback, features)))
model.add(Reshape(target_shape=(features, lookback, 1), input_shape=(lookback, features)))
Run Code Online (Sandbox Code Playgroud)
根据前面提到的答案,输入需要根据以下逻辑重新整形:
Reshape
5个输入特征现在都被视为对于TimeDistributed层的时间层当 Conv1D 应用于每个输入特征时,它认为层的形状是 (10, 1)
使用默认的“channels_last”,因此...
# Add causal layers
for dilation_rate in dilation_rates:
model.add(TimeDistributed(Conv1D(filters=filters, …
Run Code Online (Sandbox Code Playgroud) 我想重新组织下面的多行DataFrame,
1 2 3
A Apple Orange Grape
B Car Truck Plane
C House Apartment Garage
Run Code Online (Sandbox Code Playgroud)
到此单行DataFrame中。
1_A 2_A 3_A 1_B 2_B 3_B 1_C 2_C 3_C
0 Apple Orange Grape Car Truck Plane House Apartment Garage
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
我有以下两个DataFrame,
stats
:
player_id player_name gp ab run hit
28920 S. Smith 1 2 1 3
33351 T. Mancini 0 0 0 0
30267 C. Gentry 0 0 0 0
34885 H. Kim 1 0 0 0
31988 J. Schoop 0 0 0 0
5908 J.J. Hardy 1 3 0 0
Run Code Online (Sandbox Code Playgroud)
&game
:
player_id player_name gp ab run hit
28920 S. Smith 1 4 1 1
33351 T. Mancini 1 1 0 1
34885 H. Kim 1 1 2 …
Run Code Online (Sandbox Code Playgroud) python ×7
pandas ×4
dataframe ×3
keras ×2
format ×1
list ×1
lstm ×1
merge ×1
multi-index ×1
string ×1
tensorflow ×1
time-series ×1
updates ×1