1

I have a PANDAS Series of dates (as strings) and frequencies as integers:

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

But I need them as the output of events in the code below:

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)

I mean to keep my data but change the type so that I can use them in another piece of code. Thank you in advance.

woody70
  • 85
  • 9
  • 1
    Would adding a second column and converting them there work? – ti7 Oct 02 '20 at 16:59
  • My problem is that I don't know how to work with PANDAS Series, there is no column name, nothing. – woody70 Oct 02 '20 at 17:02
  • 1
    Just add it to your dataframe before making the Series – ti7 Oct 02 '20 at 17:04
  • 1
    If you just need a random row, you can randomly choose from the index and then map that back into your DF. – ti7 Oct 02 '20 at 17:06
  • 1
    You can use the pandas.to_datetime to convert the index that is as str to date. You can acess the index making dataframe.index https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.to_datetime.html – Artur Jacques Nürnberg Oct 02 '20 at 17:26

1 Answers1

1

Thank you all for helping me. I did like the code below:

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)
woody70
  • 85
  • 9