pandas merge使用

该博客内容涉及数据读取、时间序列转换和数据融合操作。使用read_data类读取特定时间段的数据,将时间数据转换为datetime对象并创建一个时间间隔索引。然后,通过left outer join将空值填充的数据框与原始数据进行合并,确保时间覆盖完整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

data_read=read_data.ReadData()

data=data_read.read_data(1638,'12 12:00:00','12 18:00:00')
datels = [datetime.strptime(x, "%Y-%m-%d %H:%M:%S") for x in data['timedata']]
data['timedata']=datels
index=pd.DatetimeIndex(start=data['timedata'].min(),end=data['timedata'].max(),freq='T')
data1=DataFrame([None]*len(index),columns=['value'])
data1['timedata']=index
merge_data=data1.merge(data,left_on='timedata',right_on='timedata',how='left')
right : DataFrame or named Series
Object to merge with.
how : {‘left’, ‘right’, ‘outer’, ‘inner’}, default ‘inner’
Type of merge to be performed.
left: use only keys from left frame, similar to a SQL left outer join; preserve key order.
right: use only keys from right frame, similar to a SQL right outer join; preserve key order.
outer: use union of keys from both frames, similar to a SQL full outer join; sort keys lexicographically.
inner: use intersection of keys from both frames, similar to a SQL inner join; preserve the order of the left keys.
on : label or list
Column or index level names to join on. These must be found in both DataFrames. If on is None and not merging on indexes then this defaults to the intersection of the columns in both DataFrames.
left_on : label or list, or array-like
Column or index level names to join on in the left DataFrame. Can also be an array or list of arrays of the length of the left DataFrame. These arrays are treated as if they are columns.
right_on : label or list, or array-like
Column or index level names to join on in the right DataFrame. Can also be an array or list of arrays of the length of the right DataFrame. These arrays are treated as if they are columns.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值