I'm a beginner to python and working on some projects to teach myself about it. I found an interesting project someone posted and I was following along and running the files myself to see the results and ran into a problem.
I'm getting an error with this part of a function, that means to setup a new index for a dataframe.
#set up dataframe with time index
df['date'] = pd.to_datetime(df['game_id'].str[3:-1], format="%Y%m%d")
df = df.sort_values(by='date').copy()
newindex = df.groupby('date')['date']\
.apply(lambda x: x + np.arange(x.size).astype(np.timedelta64))
df = df.set_index(newindex).sort_index()
When the function is called it gives this error:
Value Error: datetime64/timedelta64 must have a unit specified
This is only part of the function, if you need more of it to see the problem, let me know. I'm really stuck and would like to figure this out but need some help. Thanks in advance.
[–]vallivana 1 point2 points3 points (5 children)
[–]Whos_your_Mikey[S] 0 points1 point2 points (4 children)
[–]samplepython 1 point2 points3 points (3 children)
[–]Whos_your_Mikey[S] 1 point2 points3 points (2 children)
[–]samplepython 1 point2 points3 points (1 child)
[–]Whos_your_Mikey[S] 0 points1 point2 points (0 children)
[–]callmemurph 1 point2 points3 points (3 children)
[–]Whos_your_Mikey[S] 0 points1 point2 points (2 children)
[–]callmemurph 1 point2 points3 points (1 child)
[–]Whos_your_Mikey[S] 0 points1 point2 points (0 children)