python - Pandas changing cell values based on another cell -
i formatting data 2 different data sets. 1 of dataset reflects observation count of people in room on hour basis, second 1 count of people based on wifi logs generated in 5 minutes interval.
after merging these 2 dataframes one, run issue each hour (as "10:00:00") has data original set, other data (every 5min "10:47:14") not include data.
here how merge dataframe looks:
room time con auth capacity % count module size 0 b002 mon nov 02 10:32:06 23 23 90 nan nan nan nan` 1 b002 mon nov 02 10:37:10 25 25 90 nan nan nan nan` 12527 b002 mon nov 02 10:00:00 nan nan 90 50% 45.0 comp30520 60` 12528 b002 mon nov 02 11:00:00 nan nan 90 0% 0.0 comp30520 60`
is there way me go through dataframe , find information regarding "occupancy", "occupancycount", "module" , "size" 11:00:00 , write cells of same day , hour between 10:00:00 , 10:59:59?
that allow me have information on each row , allow me gather min()
, max()
, median()
based on 'day' , 'hour'.
to answer comment original dataframes, here there are:
first dataframe:
time room module size 0 mon nov 02 09:00:00 b002 comp30190 29 1 mon nov 02 10:00:00 b002 comp40660 53
second dataframe:
room time con auth capacity % count 0 b002 mon nov 02 20:32:06 0 0 nan nan nan 1 b002 mon nov 02 20:37:10 0 0 nan nan nan 2 b002 mon nov 02 20:42:12 0 0 nan nan nan 12797 b008 wed nov 11 13:00:00 nan nan 40 25 10.0 12798 b008 wed nov 11 14:00:00 nan nan 40 50 20.0 12799 b008 wed nov 11 15:00:00 nan nan 40 25 10.0
this how these 2 dataframes merged together:
dfinal = pd.merge(df, d3, left_on=["room", "time"], right_on=["room", "time"], how="outer", left_index=false, right_index=false)
any appreciated.
thanks lot,
-romain
somewhere start:
b = df[(df['time'] > x) & (df['time'] < y)]
selects elements within times x , y
and
df.loc[df['column_name'].isin(b)]
gives rows want (ie - between x , y) , can assign see fit. think you'll want assign values of selected rows of row number x?
hope helps.
note these function cut , paste jobs
[1] filter dataframe rows if value in column in set list of values
[2] select rows dataframe based on values in column in pandas
Comments
Post a Comment