DataFrame 加减乘除

headlist = ['a', 'b']
datalist = [[1, 2], [0,3], [3,2]]
df = pd.DataFrame(data=datalist,columns=headlist)

datalist = [[1, 3], [2, 1]]
df1 = pd.DataFrame(data = datalist, columns=headlist)

# 加
print  df.add(df1)
# nan用0填充
print  df.add(df1, fill_value = 0)

# 减
print  df.sub(df1)

# 乘
print  df.mul(df1)

# 除
print df.div(df1, fill_value = 1)

  

posted @ 2018-06-01 23:33  谭志宇  阅读(1634)  评论(0编辑  收藏  举报