csv数据合并

import torch 
import numpy as np
import pandas as pd


# 读取数据集,假设是 NumPy 二维数组(分为三个文件)
array_imu = np.loadtxt("ADIS16460.txt") 
array_gps = np.loadtxt("GNSS_RTK.pos") 
array_truth = np.loadtxt("truth.nav")


# 将 NumPy 数组转换为 Pandas DataFrame,并指定列名(原始数据没有列表头列,需自己指定)
df_imu = pd.DataFrame(array_imu, columns=['GNSSTime', 'angle_x_axis', 'angle_y_axis','angle_z_axis','velocity_x_axis','velocity_y_axis','velocity_z_axis'])  # 替换 'IMU_Column1', 'IMU_Column2', ... 为实际的列名
df_gps = pd.DataFrame(array_gps, columns=['GNSSTime', 'geodetic_latitude', 'geodetic_longitude','geodetic_height','latitude_deviation', 'longitude_deviation','height_deviation',])  # 替换 'GPS_Column1', 'GPS_Column2', ... 为实际的列名
df_truth = pd.DataFrame(array_truth, columns=['week','GNSSTime', 'geodetic_latitude_truth', 'geodetic_longitude_truth','geodetic_height_truth','velocity_north_truth', 'velocity_east_truth','velocity_down_truth','roll_truth','pitch_truth','yaw_truth',])  # 替换 'Truth_Column1', 'Truth_Column2', ... 为实际的列名



# 合并 IMU 和 GPS 数据(以gps中时间列为基准)
df_merged = pd.merge_asof(
    df_gps.sort_values(by='GNSSTime'), df_imu.sort_values(by='GNSSTime'), 
    on='GNSSTime', direction='nearest')



# 再合并真实数据(以上一个函数的时间列为基准)
df_merged = pd.merge_asof(
    df_merged, df_truth.sort_values(by='GNSSTime'),
    on='GNSSTime', direction='nearest')



# 保存合并后的数据到一个新的文件
df_merged.to_csv("wuhan_fusion2.csv", index=False)

这段代码首先以 GNSS_RTK.pos 数据集为基础,依次将 ADIS16460truth.nav 数据集与其合并。merge_asof 函数用于进行基于最近时间的模糊合并,确保每一步的合并都是基于 GNSS_RTK.pos 文件的时间。这样处理可以保证 Time 列值的一致性和准确的时间对齐。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值