How To Put The Every Start Time As 0 In Every Day For Specific Column Input Data Using Panda Python
This question is related to this question How to get time difference in specifc rows include in one column data using python Here I have three inputsX1,X2,X3. So here I want to fi
Solution 1:
Filter rows by condition and use DataFrameGroupBy.diff
for difference, last replace missing values by 0
:
df = pd.read_csv('data6 - data6.csv')
#print (df)
df.time = pd.to_datetime(df.time, format="%H:%M:%S")
df1 = df[df.x3 != 0]
df['new'] = df1['time'].dt.hour.groupby(df1['date']).diff()
df['new'] = df['new'].fillna(0).astype(int)
print(df.head(20))
date time x1 x2 x3 new
0 10/3/2018 1900-01-01 06:00:00 63 0 0 0
1 10/3/2018 1900-01-01 07:00:00 63 0 2 0
2 10/3/2018 1900-01-01 08:00:00 104 11 0 0
3 10/3/2018 1900-01-01 09:00:00 93 0 50 2
4 10/3/2018 1900-01-01 10:00:00 177 0 0 0
5 10/3/2018 1900-01-01 11:00:00 133 0 0 0
6 10/3/2018 1900-01-01 12:00:00 70 0 0 0
7 10/3/2018 1900-01-01 13:45:00 83 0 0 0
8 10/3/2018 1900-01-01 15:00:00 127 0 0 0
9 10/3/2018 1900-01-01 16:00:00 205 0 0 0
10 10/3/2018 1900-01-01 17:00:00 298 0 0 0
11 10/3/2018 1900-01-01 18:00:00 234 0 0 0
12 10/3/2018 1900-01-01 19:00:00 148 0 20 10
13 10/3/2018 1900-01-01 20:00:00 135 0 0 0
14 10/3/2018 1900-01-01 21:30:00 100 0 50 2
15 10/4/2018 1900-01-01 06:00:00 166 0 0 0
16 10/4/2018 1900-01-01 07:00:00 60 0 0 0
17 10/4/2018 1900-01-01 08:00:00 120 10 10 0
18 10/4/2018 1900-01-01 09:00:00 80 40 20 1
19 10/4/2018 1900-01-01 11:00:00 60 70 50 2
Post a Comment for "How To Put The Every Start Time As 0 In Every Day For Specific Column Input Data Using Panda Python"