At the time of data processing, especially in the big data contest, often encounter a problem is that multiple forms of merging problems, such as a form has user_id and age two fields, another form has user_id and sex two fields, to merge these two tables into only user_id, Age, sex three fields of the table what to do, the ordinary stitching is not possible, because user_id each row is not the corresponding, like the building blocks of horizontal stitching is certainly not. There is a merge function in pandas to do this practical function, the word "merge" will be a bit of SQL language should not be unfamiliar.
Let's talk about the merge function:
DF = Pd.merge (DF1, DF2, how= ' left ', on= ' user_id ')
Usage is very simple, say the latter two parameters, how= "" parameter indicates which table key, above the how= "left" to indicate the table DF1, and key is on= "" parameter
How= "left" that is, keep the user_id field of all information, not increase or decrease, but stitching only the DF2 table and df1 in the user_id field of the intersection of the part of the merge on it, if there is df2 in the user_id does not appear in DF1, Just discard the sample and leave it out of the process.
If you are merging multiple keys:
DF = Pd.merge (DF1, DF2, how= ' left ', on=[' user_id ', ' sku_id ')
But if you want to simply "stitch" instead of merging, use the concat function :
DF = Pd.concat ([Df_user, Dummies_sex, Dummies_age, Dummies_level], Axis=1)
This preserves all the information of these forms, the parameter Axis=1 represents the column concatenation, and the axis=0 represents the row stitching.
To ensure that the number of rows on the back of the form is the same, and each row of the corresponding key is the same, column stitching becomes meaningful