Pandas.merge()函数用法及源码

Python数据分析博文汇总

字段匹配:将不同结构的数据框,按照一定的条件进行合并

函数用法:merge(df1, df2, column of df1, column of df2)

import pandas;
from pandas import read_csv;
items = read_csv(
    "E:\\pythonlearning\\datacode\\firstpart\\4\\4.12\\data1.csv", 
    sep='|', 
    names=['id', 'comments', 'title']
);
prices = read_csv(
    "E://pythonlearning//datacode//firstpart//4//4.12//data2.csv", 
    sep='|', 
    names=['id', 'oldPrice', 'nowPrice']
);
itemPrices = pandas.merge(
    items, 
    prices, 
    left_on='id', 
    right_on='id'
);#以'id'列用基准,合并数据框

运行前12行得到:



再运行剩余行:


源代码:https://download.csdn.net/download/w_weiying/10427108

猜你喜欢

转载自blog.csdn.net/w_weiying/article/details/80394036
今日推荐