Creating Time Series Data Frames

Asked 1 years ago, Updated 1 years ago, 461 views

output —DatetimeIndex('2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04',
'2022-01-05', '2022-01-06', 2022-01-07', '2022-01-08', ...
'2022-01-29', '2022-01-30', '2022-01-31',

"If you want to change the time to ""2022-01-010:00"" format,
How should I fix it?

2. If you want to enter the same value every day,
What kind of code should I write?

Enter a description of the image here

python pandas

2023-02-28 06:34

1 Answers

import pandas as pd

df = pd.DataFrame({
  'A': pd.date_range(start='2022-01-01', end='2022-01-31', freq='D').strftime('%Y/%-m/%-d%-H:%M',
  'B': 100,
})

df.info()
print(df)

# <class'pandas.core.frame.DataFrame'>
# RangeIndex: 31 entries, 0 to 30
# Data columns (total 2 columns):
#  # Column Non-Null Count Dtype 
# ---  ------  --------------  ----- 
#  0 A 31 non-null object
#  1 B 31 non-null int 64 
# dtypes: int64(1), object(1)
# memory usage —624.0+bytes
#
#                  AB
# 0    2022/1/1 0:00  100
# 1    2022/1/2 0:00  100
# 2    2022/1/3 0:00  100
# 3    2022/1/4 0:00  100
# 4    2022/1/5 0:00  100
# 5    2022/1/6 0:00  100
#              :
#              :


2023-02-28 07:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.