我有这个df:
df1
t0
ACER 50
BBV 20
ACC 75
IRAL 25
DECO 58
另一方面:
df2
t1
ACER 50
BBV 20
CEL 0
DIA 25
我期待添加两个dfs以获得以下输出:
df3
t2
ACER 100
BBV 40
ACC 75
IRAL 25
DECO 58
DIA 25
CEL 0
基本上是在df1
和df2
中添加了常见索引值,并包括df1
我试过了
d1.add(df2)
但是出现了Nan值,我还想到在合并dfs时,用零替换Nans并添加列,但我想也许有很多代码可以执行此操作。
答案 0 :(得分:2)
使用concat和sum
df3 = pd.concat([df1, df2], axis=1).sum(1)
ACC 75.0
ACER 100.0
BBV 40.0
CEL 0.0
DECO 58.0
DIA 25.0
IRAL 25.0
答案 1 :(得分:1)
你实际上是在正确的轨道上,你只需要 <form [formGroup]="form">
<!-- OLD PASSWORD -->
<div class="form-group">
<label for="">Old Password</label>
<input formControlName="oldPassword" type="password" class="form-control">
<div
*ngIf="oldPassword.touched && oldPassword.invalid"
class="alert alert-danger">
<div *ngIf="oldPassword.errors.required">
Old password is required.
</div>
</div>
</div>
<!-- NEW PASSWORD -->
<div class="form-group">
<label for="">New Password</label>
<input formControlName="newPassword" type="password" class="form-control">
<div
*ngIf="newPassword.touched && newPassword.invalid"
class="alert alert-danger">
<div *ngIf="newPassword.errors.required">New password is required.</div>
</div>
</div>
<!-- CONFIRM PASSWORD -->
<div class="form-group">
<label for="">Confirm Password</label>
<input formControlName="confirmPassword" type="password" class="form-control">
<div
*ngIf="confirmPassword.touched && confirmPassword.invalid"
class="alert alert-danger">
<div *ngIf="confirmPassword.errors.required">Confirm password is required.</div>
</div>
</div>
<button class="btn btn-primary">Change Password</button>
</form>
:
fill_value=0
请注意,您必须将df1.t0.add(df2.t1, fill_value=0).to_frame('t2')
t2
ACC 75.0
ACER 100.0
BBV 40.0
CEL 0.0
DECO 58.0
DIA 25.0
IRAL 25.0
个对象添加到一起以防止错位问题。