将日期列表作为字符串转换为 PANDAS DatetimeIndex

Convert a List of Dates as String to PANDAS DatetimeIndex

我有一个 PANDAS 系列日期(作为字符串)和频率作为整数:

date    
2020-02-02  24
2020-02-03  43
2020-02-07  465
2020-02-08  123
2020-02-09  234

但我需要它们作为以下代码中 events 的输出:

all_days = pd.date_range('1/01/2020', periods=300, freq='D')
days = np.random.choice(all_days, 200)
events = pd.Series(np.random.randn(len(days)), index=days)

我的意思是保留我的数据但更改类型以便我可以在另一段代码中使用它们。提前谢谢你。

谢谢大家对我的帮助。我确实喜欢下面的代码:

import numpy as np; np.random.seed(sum(map(ord, 'calmap')))
import pandas as pd
import calmap

all_days = pd.date_range('1/01/2020', periods=300, freq='D')
days = np.random.choice(all_days, 200)
date_index = pd.to_datetime(dates_count.index)
maximum = max(dates_count.values)
minimum = min (dates_count.values)
events = pd.Series(((dates_count.values-minimum)*2/(maximum - minimum))-1, index=date_index)