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

Python 将日期列表转换为字符串DatetimeIndex,python,pandas,datetimeindex,Python,Pandas,Datetimeindex,我有一系列日期(作为字符串)和频率作为整数: date 2020-02-02 24 2020-02-03 43 2020-02-07 465 2020-02-08 123 2020-02-09 234 但我需要它们作为以下代码中事件的输出: all_days = pd.date_range('1/01/2020', periods=300, freq='D') days = np.random.choice(all_days, 200) events = pd.Series(

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

date    
2020-02-02  24
2020-02-03  43
2020-02-07  465
2020-02-08  123
2020-02-09  234
但我需要它们作为以下代码中事件的输出:

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)

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

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

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)

添加第二列并在那里转换行吗?我的问题是我不知道如何使用PANDAS系列,没有列名,什么都没有。只需在创建系列之前将其添加到数据帧中,如果您只需要一个随机行,您可以从索引中随机选择,然后将其映射回DF。您可以使用pandas.to_datetime将作为str的索引转换为date。您可以访问制作dataframe.index的索引