我有两个数据框,想将它们合并到一个函数中。
module HCG(I,e,O);
input [4:1] I; // input BCD
input [7:1] e; // noise simulation
wire [7:1] X; // Hamming code
wire [7:1] Y; // Hamming code after addition of noise
wire [3:1] P; // Parity at start
wire [3:1] S; // Parity at end
integer b; // the error bit
reg [7:1] Z; // corrected hamming code
output [4:1] O; // corrected output
assign X[1]=I[1]^I[2]^I[4]; // Hamming code generator
assign X[2]=I[1]^I[3]^I[4];
assign X[3]=I[1];
assign X[4]=I[2]^I[3]^I[4];
assign X[5]=I[2];
assign X[6]=I[3];
assign X[7]=I[4];
assign P[1]=X[1]; // Parity at start
assign P[2]=X[2];
assign P[3]=X[4];
assign Y[1]=e[1]^X[1]; // noise added
assign Y[2]=e[2]^X[2];
assign Y[3]=e[3]^X[3];
assign Y[4]=e[4]^X[4];
assign Y[5]=e[5]^X[5];
assign Y[6]=e[6]^X[6];
assign Y[7]=e[7]^X[7];
assign S[1]=Y[3]^Y[5]^Y[7]; // Parity at end
assign S[2]=Y[3]^Y[6]^Y[7];
assign S[3]=Y[5]^Y[6]^Y[7];
always @( *)
begin
b=0; // initialize b to zero
Z=Y; // initialize Z1~Z7 with Y1~Y1
if(S[1]!=P[1])
b=b+1;
if(S[2]!=P[2]) // b is cumulative if each of the conditions is true
b=b+2;
if(S[3]!=P[3])
b=b+4;
if(b!=0)
Z[b]=~(Y[b]); // correct the incorrect b'th-bit
end
assign O[1]=Z[3]; // assigning outputs
assign O[2]=Z[5];
assign O[3]=Z[6];
assign O[4]=Z[7];
endmodule
结果:
df = pd.DataFrame(data={'col1': [1, 2], 'A': ['A', 'A']})
df_temp = pd.DataFrame(data={'col1': [1, 2], 'B': ['B', 'B']})
def func(df):
dx = df.merge(df_temp, how='left', left_on='col1', right_on='col1')
return dx
df.pipe(func)
print(df)
结果是得到相同的原始df。 df_temp的B列未如我所期望的那样被添加到数据帧df中。为什么这不起作用?
答案 0 :(得分:1)
您忘记将df分配给管道应用函数(func)的结果。
OLD: df.pipe(func)
NEW: df=df.pipe(func)