How to divide hours in 15m intervals and distribute the values ​of each hour in python?

Asked
Active3 hr before
Viewed126 times

7 Answers

valuespythonintervalshours
90%

Valid date strings can be converted to datetime objects using to_datetime function or as part of read functions,,Some other advantages are the convenient subsetting of time period or the adapted time scale on plots

Example_snippet/controller/utility/_values.js/ In [1]: import pandas as pd I. . .
In[1]: import pandas as pd

In[2]: import matplotlib.pyplot as plt
load more v
88%

Thanks for contributing an answer to Unix & Linux Stack Exchange!,Is there any way I can get the current 15 minute interval using the date command or similar ?,Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems, It only takes a minute to sign up

Example_snippet/controller/utility/_values.js/ curdate=`date "+%s"` curquarte. . .
curdate = `date "+%s"`
curquarter = $(($curdate - ($curdate % (15 * 60))))
date - d "@$curquarter"
Step 2 continued with date -d"1970-01-01 $curquarter. . .
date - d "1970-01-01 $curquarter seconds UTC"
load more v
72%

What determines the time intervals returned by GROUP BY time() queries?,Why don’t my GROUP BY time() queries return timestamps that occur after now()?,The time intervals returned by GROUP BY time() queries conform to the InfluxDB database’s preset time buckets or to the user-specified offset interval,,Why does my query return epoch 0 as the timestamp?

Example_snippet/controller/utility/_values.js/ $ influxd version InfluxDB v1. . .
$ influxd version

InfluxDB v1 .8 .9(git: master b7bb7e8359642b6e071735b50ae41f5eb343fd42)
load more v
65%

This process of changing the time period that data are summarized for is often called resampling,,Often you need to summarize or aggregate time series data by a new time period

Example_snippet/controller/utility/_values.js/ # Import necessary packages im. . .
# Import necessary packages
import os
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import earthpy as et

# Handle date time conversions between pandas and matplotlib
from pandas.plotting
import register_matplotlib_converters
register_matplotlib_converters()

# Use white grid plot background from seaborn
sns.set(font_scale = 1.5, style = "whitegrid")
load more v
75%

For example, per_hour() converts the field value so that it is a rate per hour, or sum()/<hours in the span>, If your chart span ends up being 30m, it is sum()*2

Example_snippet/controller/utility/_values.js/ eval. . .
eval
Step 2 continued with limit. . .
limit
Step 3 continued with agg. . .
agg
load more v
40%

make 4 duplicate rows for each hour, and then add a ranking column for each hour, – staticor Dec 21 '20 at 15:39 , i have some difficulties in programming in python

Example_snippet/controller/utility/_values.js/ x = df.Temperature.str.split(". . .
x = df.Temperature.str.split(",", expand = True)
Step 2 continued with 0 1 0 19 11 1 18 6. . .
    0 1
    0 19 11
    1 18 67
    2 18 22
    3 17 77
Step 3 continued with y = x[0].astype(int).diff().di. . .
y = x[0].astype(int).diff().div(4).fillna(x.iloc[0, 0]).astype(float).cumsum()
Step 4 continued with 0 19.00 1 18.75 2 18.. . .
0 19.00
1 18.75
2 18.75
3 18.50
Name: 0, dtype: float64
Step 5 continued with df[['temp1', 'temp2']] = df.Te. . .
df[['temp1', 'temp2']] = df.Temperature.str.split(",", expand = True)
df['temp1'] = df['temp1'].astype(int)
df['temp2'] = df['temp2'].astype(int)

u = pd.to_datetime(df['hour'], format = '%H:%M') #.dt.hour
df['hr'] = u.dt.hour
df = df.set_index(u)
df1 = df.resample('900s').pad()
Step 6 continued with df['hour'] = pd.to_datetime(df. . .
df['hour'] = pd.to_datetime(df['hour'], format = '%H:%M')
df.set_index('hour', inplace = True)
v = df.resample('15T').bfill().reset_index()

v[['temp1', 'temp2']] = v.Temperature.str.split(",", expand = True)
v['temp1'] = v['temp1'].astype(int)
v['temp2'] = v['temp2'].astype(int)

t = v.groupby(v['hour'].dt.hour)

def calc(val1, val2):
   diff1 = (val1['temp1'] - val2['temp1'])
diff1.iloc[0] = val1['temp1'].iloc[0] * 4

diff2 = (val1['temp2'] - val2['temp2'])
diff2.iloc[0] = val1['temp2'].iloc[0] * 4

t1_group = diff1.div(4).cumsum()
t2_group = diff2.div(4).cumsum()

return list(zip(t1_group, t2_group))

concat_res = []
for _, gr in t:
   concat_res.append(calc(gr, gr.iloc[0]))

flatten = lambda t: [item
   for sublist in t
   for item in sublist
]
v['Temperature'] = flatten(concat_res)
v = v.drop(['temp1', 'temp2'], axis = 1)
load more v
22%

This is the simplest use of the above strategy, To count employees in each department based on employee information, for instance:,To get the number of employees, the average salary and the largest age in each department, for instance:,There are more complicated computing goals

Example_snippet/controller/utility/_python.js/ import pandas as pd#Import da. . .
import pandas as pd #Import dataemployee = pd.read_csv("Employees.csv") #Grouping and perform count over each groupdept_emp_num = employee.groupby('DEPT')['DEPT'].count() print(dept_emp_num)
load more v