根据时间将多个数据框连接到file.txt python [英] Joining Multiple data frame to file.txt python based on time

查看:76
本文介绍了根据时间将多个数据框连接到file.txt python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据框如下所示

       X    Y  Z    Value        Time
0      18   55  1      70        100 
1      18   55  2      67        200
2      18   57  2      75        300
3      18   58  1      35        400
4      19   54  2      70        500

        X    Y  Z    Value       Time
0      17   15  1      40        100  
1      17   60  2      67        200
2      17   57  5      75        300 
3      17   79  1      35        400
4      17   54  2      70        500

       X    Y  Z    Value        Time  # Time in milliseconds 
0      15   35  1      70        100
1      15   55  2      67        200
2      15   91  8      75        300 
3      15   58  1      35        400
4      15   60  2      70        500

我想将其保存为这种格式的文本文件,以尝试在任何特定时间将来自不同数据帧的每一行分组.

I want to save it as a text file with this format trying to group each row from different data frame for any particular time instant.

X    Y  Z     Value  
18   55  1      70
17   15  1      40
15   35  1      70

Time: 100

X    Y  Z     Value  
18   55  2      67
17   60  2      67
15   55  2      67

Time: 200       # time grows 


....

推荐答案

使用concat然后groupby拆分

l=[df1,df2,df3]
for y, x in pd.concat(l).groupby('Time'):
    x.drop('Time',1).to_csv('df'+str(y)+'.csv')

这篇关于根据时间将多个数据框连接到file.txt python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆