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(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)
推荐阅读
- java - 如何在不依赖 Pivotal GemFire 缓存的情况下启动 Spring Boot 应用程序
- java - ArrayList 只识别第一个元素
- tsql - 当另一列重复时连接列
- vuejs2 - 如何用另一个“观察者”更新 vue“观察者”的所有属性
- python - 如何在 DataFrame 中插入一行(列表)?
- javascript - 将 html 文本框屏蔽为美国电话号码格式
- ibm-cloud-private - ibm cloud private 2.1.0.3 失败,出现“等待 MongoDB 启动”错误
- html - 如何为已经存在的技能栏设置动画
- php - 可以在 Oracle Linux 7 上的 PHP 7.1 中安装 mcrypt 吗?
- android - 简单的矢量可绘制为 android