-2
  1. I have some dataset. Let's presume it is:

    dataset = pd.read_csv('some_stock_name_here.csv', index_col=['Date'], parse_dates=['Date'])

The csv file has 2500 observation(Date and Close price position) and I want to create a new csv file which inlude the same time series but with much less frequency data on the raw. For example every 40-th of the previous? How can I do this? 2. Also I'm wondering whether I could manipulate that frequency within the notebook without creating new csv file. Thanks in advance.

  • Have you done some research on that problem by yourself? Have you tried anything to solve the problem by yourself? If so, please share your approach. As you are already using the pandas data analysis library maybe you should have a look at [pandas.Series.resample()](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.resample.html). – jequ Aug 23 '20 at 19:15
  • Also [Resample Daily Data to Monthly with Pandas (date formatting)](https://stackoverflow.com/questions/42191697) – Trenton McKinney Aug 23 '20 at 19:30

1 Answers1

1

You can slice your df using iloc:
Going over all rows and taking those at indexes that are divisible with X.

X = 40
df.iloc[::X]

Saving data-frame is achieved by the following code:

df.to_csv(FILE_PATH_HERE)
Aviv Yaniv
  • 6,188
  • 3
  • 7
  • 22