pandas表数据处理

import pandas as pd
import numpy as np

df = pd.DataFrame(
    {
        "id":[1001,1002,1003,1004,1005,1006],
        "date":pd.date_range('20130102', periods=6),
        "city":['Beijing ', 'SH', ' guangzhou ', 'Shenzhen', 'shanghai', 'BEIJING '],
        "age":[23,44,54,32,34,32],
        "category":['100-A','100-B','110-A','110-C','210-A','130-F'],
        "price":[1200,np.nan,2133,5433,np.nan,4432]
    },
  columns =['id','date','city','category','age','price'])

df1=pd.DataFrame({"id":[1001,1002,1003,1004,1005,1006,1007,1008],
"gender":['male','female','male','female','male','female','male','female'],
"pay":['Y','N','Y','Y','N','Y','N','Y',],
"m-point":[10,12,20,40,40,40,30,20]})
print(df1)

#数据表合并
df_inner = pd.merge(df,df1,how='inner')
df_left = pd.merge(df,df1,how='left')
df_right = pd.merge(df,df1,how='right')
df_outer = pd.merge(df,df1,how='outer')
print('*************')
print(df_inner,end='\n')
print('*************')
print(df_left,end='\n')
print('*************')
print(df_right,end='\n')
print('*************')
print(df_outer,end='\n')

#append
result = df.append(df1)
print('输出追加的表数据(两张表的数据直接拼接在一起,缺失值为NaN)')
print(result)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值