0

I have some data that I have read in the following way:

filename = 'minamORE.txt'
f1 = open(filename, 'r')
lines = f1.readlines()

mOREt = []
mOREdis = []



import pandas as pd

data = pd.read_csv('minamORE.txt',sep='\t',header=None,usecols=[2,3])
mOREdate = data[2].values
mOREdis = data[3].values

mOREdis = np.float64(mOREdis)
mOREdate = np.array(mOREdate, dtype = "datetime64")

The date array spans over 20 years and has an entry for each day. I would like to some how group all of the January measurements with all of the other January measurements and so on through December.

I'm not experienced enough with python to really think of any solution but to manually do it as follows: (NOTE: October 1 is the first measurement) OCTMeasurements = [mOREdis[0,31], mOREdis[0+365, 31+365], ..... [0+20*365, 31+20*365]

For obvious reasons, I'd like to avoid doing this if possible.

The dates are stored in the following format: YYYY-MM-DD.

If I could somehow refer to the values base don the MM value I feel this would be the most efficient way, but again, inexperience renders me unable to do so.

probat
  • 1,422
  • 3
  • 17
  • 33
BAKKAB
  • 51
  • 4
  • https://stackoverflow.com/questions/39400115/python-pandas-group-by-date-using-datetime-data – user1558604 Dec 07 '19 at 19:58
  • You should use a `with` statement when working with open files: https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files. At the very least you should close the file once you are done with it. – wwii Dec 07 '19 at 20:11
  • Are you using Pandas just to read the csv file? or are you doing other things with the DataFrame? – wwii Dec 07 '19 at 20:13
  • Here is an SO Q&A that you could use as a starting point if you would like to do more with the DataFrame you have made: [pandas dataframe groupby datetime month](https://stackoverflow.com/questions/24082784/pandas-dataframe-groupby-datetime-month) – wwii Dec 07 '19 at 20:25

0 Answers0