Understanding Time Series Horizontal Combination Questions

Asked 1 years ago, Updated 1 years ago, 395 views

There are two CSV files: area1.csvarea2.csv
There is no item name in the time column, so
If I want to combine horizontally based on time, how can I modify it?
I would appreciate it if you could let me know!
df1 = pd.read_csv(area1.csv)
df2=pd.read_csv(area2.csv)
df3=pd.concat([df1,df2],axis=1)
df3.to_csv(area3.csv,index=False,encoding='utf-8')

Enter a description of the image here

python pandas

2023-02-17 15:10

1 Answers

index_col=0,parse_dates=True allows you to read the time string as an index, so you can just combine the rest.
Also, when to_csv, output the index as well.

import pandas as pd
from io import StringIO

s1="",r1
2023-02-01T07:00+0900,1
2023-02-01T07:30 + 0900, 2
2023-02-01T08:00+0900,3"
df1 = pd.read_csv (StringIO(s1), index_col=0, parse_dates=True)

s2="",r5
2023-02-01T07:00+0900,11
2023-02-01T07:30+0900,22
2023-02-01T08:00+0900,33"
df2 = pd.read_csv (StringIO(s2), index_col=0, parse_dates=True)

df3=pd.concat([df1,df2],axis=1)
df3.to_csv('ret.csv', encoding='utf-8')


2023-02-17 15:15

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.