I have a following analysis.py
file. The function group_analysis
changes the datetime index of df_input
by the Count
column of df_input
# analysis.py
import pandas as pd
def group_analysis(df_input):
df_input.index = df_input.index - pd.to_timedelta(df_input.Count, unit = 'days')
df_ouput = df_input.sort_index()
return df_ouput
def test(df):
df = df + 1
return df
And I have a following dataframe.
x = pd.DataFrame(np.arange(1,14), index = pd.date_range('2020-01-01', periods = 13, freq= 'D'), columns = ['Count'])
Count
2020-01-01 1
2020-01-02 2
2020-01-03 3
2020-01-04 4
2020-01-05 5
2020-01-06 6
2020-01-07 7
2020-01-08 8
2020-01-09 9
2020-01-10 10
2020-01-11 11
2020-01-12 12
2020-01-13 13
When I run the following code,
import analysis
y = analysis.group_analysis(x)
the datetime index of both x and y are changed (and so, x.equals(y)
is True
). Why group_analysis
changes the both the input and output datetime index? And how can I make it to change only the datetime index of y
(but not x
)?
However, when running the following code, x
does not change (so, x.equals(y)
is True
)
import analysis
y = analysis.test(x)
EDIT: analysis.test(df) is added.