我有一个像这样的“单行”数据框:
Value 1 Value 2 Value 3
code
123 0 3 231
Run Code Online (Sandbox Code Playgroud)
我想把零值变成空,所以它看起来像这样:
Value 1 Value 2 Value 3
code
123 3 231
Run Code Online (Sandbox Code Playgroud)
我怎么能那样做?
我有以下pandas DataFrame,名为main_frame:
target_var input1 input2 input3 input4 input5 input6
Date
2013-09-01 13.0 NaN NaN NaN NaN NaN NaN
2013-10-01 13.0 NaN NaN NaN NaN NaN NaN
2013-11-01 12.2 NaN NaN NaN NaN NaN NaN
2013-12-01 10.9 NaN NaN NaN NaN NaN NaN
2014-01-01 11.7 0 13 42 0 0 16
2014-02-01 12.0 13 8 58 0 0 14
2014-03-01 12.8 13 15 100 0 0 24
2014-04-01 13.1 0 11 50 34 0 18
2014-05-01 12.2 12 14 …Run Code Online (Sandbox Code Playgroud) 我正在使用Keras来预测时间序列.作为标准,我使用了20个时代.我想知道我的神经网络为20个时期中的每一个预测了什么.
通过使用model.predict,我得到了最后的预测.但是我想要所有的预测,或者至少是最后的10个预测(具有可接受的错误级别).
要访问我正在尝试Keras的ModelCheckpoint函数,但是之后我无法访问它.我正在使用以下代码:
model=Sequential()
model.add(GRU(input_dim=col,init='uniform',output_dim=20))
model.add(Dense(10))
model.add(Dense(5))
model.add(Activation("softmax"))
model.add(Dense(1))
model.compile(loss="mae", optimizer="RMSprop")
checkpoint=ModelCheckpoint(filepath='/Users/Alex/checkpoint.hdf5')
model.fit(X=predictor_train, y=target_train, nb_epoch=20, batch_size=batch,validation_split=0.1) #best validation split at 0.1
model.evaluate(X=predictor_train, y=target_train,batch_size=batch,show_accuracy=True)
print checkpoint
Run Code Online (Sandbox Code Playgroud)
客观地说,我的问题是:
我希望在运行代码后,我会在文件夹/ Users/Alex中找到一个名为checkpoint.hdf5的文件,但是我没有.我错过了什么?
当我打印checkpoint出我得到的是一个keras.callbacks.ModelCheckpoint object at 0x117471290.有没有办法打印我想要的东西?代码怎么样?
非常感激您的帮忙 :)
我有这个数据框:
Code Mark
0 Abd 43212312312
1 Charles de Gaulle
2 Carlitos 4132411
3 Antonio
Run Code Online (Sandbox Code Playgroud)
如果代码列中字符串的最后 5 个字符是数字,我希望 'Mark' 是 'A',所以它看起来像这样:
Code Mark
0 Abd 43212312312 A
1 Charles de Gaulle
2 Carlitos 4132411 A
3 Antonio
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用isnumeric,但我不断收到 AttributeError:'Series' object has no attribute 'isnumeric'
有人可以帮忙吗?
我有以下DataFrame:
Value 1lag
Date
2005-04-01 258.682029 214.382786
2005-05-01 173.253998 258.682029
2005-06-01 244.432029 173.253998
2005-07-01 213.706019 244.432029
2005-08-01 213.670665 213.706019
Run Code Online (Sandbox Code Playgroud)
这些是两个时间序列的绝对值.但是,我不想要那些绝对值,我想要它们的变体,所以它们看起来像这样:
Value 1lag
Date
2005-04-01 NaN NaN
2005-05-01 0.3302 -0.2066
2005-06-01 -0.4108 0.3302
2005-07-01 0.1257 -0.4108
2005-08-01 0.0002 0.1257
Run Code Online (Sandbox Code Playgroud)
有这么简单的命令吗?如果没有,你的建议是什么?
我想加入两个数据框。已经尝试过 concat、merge 和 join,但我应该做错了什么。
df 1:
index cnpj country state
1 7468 34 23
4 3421 23 12
7 2314 12 45
df 2:
index cnpj street number
2 7468 32 34
5 3421 18 89
546 2314 92 73
Run Code Online (Sandbox Code Playgroud)
我希望使用“cnpj”作为“连接键”合并它们并保留 df1 的索引。它应该是这样的:
df 1:
index cnpj country state street number
1 7468 34 23 32 34
4 3421 23 12 18 89
7 2314 12 45 92 73
Run Code Online (Sandbox Code Playgroud)
关于如何做到这一点的任何建议?
我试图根据像这样的数据框中的人的大小来推断分类:
Size
1 80000
2 8000000
3 8000000000
...
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像这样:
Size Classification
1 80000 <1m
2 8000000 1-10m
3 8000000000 >1bi
...
Run Code Online (Sandbox Code Playgroud)
我理解理想的过程是应用这样的lambda函数:
df['Classification']=df['Size'].apply(lambda x: "<1m" if x<1000000 else "1-10m" if 1000000<x<10000000 else ...)
Run Code Online (Sandbox Code Playgroud)
我检查了一些关于lambda函数中多个ifs的帖子,这里是一个示例链接,但是这个synthax在多个ifs语句中由于某种原因不适合我,但是它在单个if条件下工作.
所以我尝试了这个"非常优雅"的解决方案:
df['Classification']=df['Size'].apply(lambda x: "<1m" if x<1000000 else pass)
df['Classification']=df['Size'].apply(lambda x: "1-10m" if 1000000 < x < 10000000 else pass)
df['Classification']=df['Size'].apply(lambda x: "10-50m" if 10000000 < x < 50000000 else pass)
df['Classification']=df['Size'].apply(lambda x: "50-100m" if 50000000 < x < 100000000 else pass)
df['Classification']=df['Size'].apply(lambda x: …Run Code Online (Sandbox Code Playgroud) 考虑到输入总是有一些空白单元格并且可能存在重复值,我正在尝试将数组转换为没有空白单元格的单列。我正在尝试使用FLATTEN,但它保留了空白,并且 UNIQUE 会杀死重复的值,所以我无法使用。
我还考虑过使用类似的东西FLATTEN(QUERY(X:X, "select * WHERE col1,col2,col3,col4,col5 IS NOT NULL"),但列数可能是动态的,所以我不能准确地说出要使用哪些列。
我的输入:
期望的输出:
有什么线索吗?
我有这样的数据帧
id 2013 Profits 2001 Revenues 1999 Assets...
31 xxxx xxxx xxxx
...
Run Code Online (Sandbox Code Playgroud)
我想删除不以'201'开头的列(我只想保留数据2010和转发).
我怎样才能做到这一点?
我有这两个列表,具有相同的 len:
owner=["John","John","Mark","Bill","John","Mark"]
restaurant_number=[0,2,3,6,9,10]
Run Code Online (Sandbox Code Playgroud)
我想把它变成一个通知每个所有者的 restaurant_number 的字典:
d={"John":[0,2,9],"Mark":[3,10],"Bill":[6]}
Run Code Online (Sandbox Code Playgroud)
我可以用丑陋的方式做到这一点:
unique=set(owner)
dict={}
for i in unique:
restaurants=[]
for k in range(len(owner)):
if owner[k] == i:restaurants.append(restaurant_number[k])
dict[i]=restaurants
Run Code Online (Sandbox Code Playgroud)
有没有更pythonic的方法来做到这一点?
python ×9
pandas ×7
dataframe ×3
apply ×1
dictionary ×1
if-statement ×1
keras ×1
lambda ×1
list ×1
scikit-learn ×1
string ×1