logo
down
shadow

python add hourly data [1-24] to datetime data


python add hourly data [1-24] to datetime data

By : Panicko Lawrence
Date : November 21 2020, 04:01 AM
hope this fix your issue I have the following data structure in a dataframe: , Given
code :
>>> df                                                                                                                 
         Date  Hour
0  01/01/2016     1
1  01/01/2016     2
2  01/01/2016     3
3  01/01/2016     4
>>> df['Date'] = pd.to_datetime(df['Date']) # pick dayfirst=True or False in your code                                                                            
>>> df                                                                                                                 
        Date  Hour
0 2016-01-01     1
1 2016-01-01     2
2 2016-01-01     3
3 2016-01-01     4
>>> df['DateTime'] = df['Date'] + pd.to_timedelta(df['Hour'], 'h')                                                     
>>> df                                                                                                                 
        Date  Hour            DateTime
0 2016-01-01     1 2016-01-01 01:00:00
1 2016-01-01     2 2016-01-01 02:00:00
2 2016-01-01     3 2016-01-01 03:00:00
3 2016-01-01     4 2016-01-01 04:00:00


Share : facebook icon twitter icon
Finding a more elegant was to aggregate hourly data to mean hourly data using zoo

Finding a more elegant was to aggregate hourly data to mean hourly data using zoo


By : user2509196
Date : March 29 2020, 07:55 AM
hop of those help? I have a chunk of data logging temperatures from a few dozen devices every hour for over a year. The data are stored as a zoo object. I'd very much like to summarize those data by looking at the average values for every one of the 24 hours in a day (1am, 2am, 3am, etc.). So that for each device I can see what its average value is for all the 1am times, 2am times, and so on. I can do this with a loop but sense that there must be a way to do this in zoo with an artful use of aggregate.zoo. Any help? , Calculate the hour for each time point and then aggregate by that:
code :
hr <- as.numeric(format(time(x.zoo), "%H"))
ag <- aggregate(x.zoo, hr, mean)
dim(ag)
## [1] 24  5
library(chron)
ag <- aggregate(x.zoo, hours, mean)
Extracting hourly data from 15 minutes interval data in python pandas

Extracting hourly data from 15 minutes interval data in python pandas


By : pangkalan data
Date : March 29 2020, 07:55 AM
seems to work fine I have a dataframe df: , Option 1
You can use groupby:
code :
(df.groupby(['Year','Month','Day','Hour'])['Reading']
    .sum()
    .reset_index()
    .assign(Minutes=0)
    .reindex_axis(['Year','Month','Day','Hour','Minutes','Reading'],axis=1))
   Year  Month  Day  Hour  Minutes  Reading
0  2011      1    1     0        0      1.6
1  2011      1    1     1        0      1.1
(df.set_index(['Year','Month','Day','Hour'])['Reading']
    .sum(level=[0,1,2,3])
    .reset_index()
    .assign(Minutes=0)
    .reindex_axis(['Year','Month','Day','Hour','Minutes','Reading'],axis=1))
   Year  Month  Day  Hour  Minutes  Reading
0  2011      1    1     0        0      1.6
1  2011      1    1     1        0      1.1
Rails + PostgreSQL group data hourly with datetime

Rails + PostgreSQL group data hourly with datetime


By : user1935037
Date : March 29 2020, 07:55 AM
Does that help Group by extracted hour from created_at, you will need to aggregate all the other data that you want to display as well,
code :
YourModel.select("EXTRACT(hour FROM created_at) AS hour_created_at")
         .group("hour_created_at")
averaging 2 decades of data on 6 hourly timestep using netcdf data and python

averaging 2 decades of data on 6 hourly timestep using netcdf data and python


By : John
Date : March 29 2020, 07:55 AM
this will help Indeed there is not a very well documented way of doing this. Note also that dayofyear may not be exactly what you expect it to be.
In lieu of being able to use groupby with multiple levels (e.g. see this answer regarding how to do something similar to what you are asking in pandas), which is not available yet in xarray, a reasonably clean way of solving this kind of problem is to define a new coordinate for grouping that represents the "time of year" for each time in your Dataset.
code :
ds['hourofyear'] = xr.DataArray(ds.indexes['time'].strftime('%m-%d %H'), coords=ds.time.coords)
result = ds.groupby('hourofyear').mean('time')
How to use groupby or resample to downsample hourly data to group data according to day hour index of year in python?

How to use groupby or resample to downsample hourly data to group data according to day hour index of year in python?


By : user3632316
Date : March 29 2020, 07:55 AM
Does that help I think you are asking for the same thing as in a question I answered earlier. In short, I think the cleanest approach in xarray at the moment is to use strftime to generate a coordinate with the "hourofyear" values for each date and use groupby on that:
code :
ds['hourofyear'] = xr.DataArray(ds.time.dt.strftime('%m-%d %H'), coords=ds.time.coords)
result = ds.groupby('hourofyear').mean('time')
Related Posts Related Posts :
  • Creating a Dataframe of Proportions
  • Scrapy with dynamic captcha
  • In python, how do I get urllib to recognize multiple lines in a string as separate URLs?
  • Add prefix and suffix to each element of a nested list
  • Generate string set from csv file in Python
  • Custom usage message for many-valued argument
  • Python Class, how to skip a wrong entry and proceed to next entry
  • Numpy efficient way to parse array of string
  • Kivy , Python: Update Label on_file_drop
  • What does it mean if a deeper conv layer converges first?
  • Selecting User in client.send_message() from arg list
  • python slicing multi levels list of dict using list comprehension
  • Value Error problem with multicell Dimensions must be equal, but are 20 and 13
  • How to print a board with coordinates?
  • Keras LSTM shape doesn't contain length of sequence
  • Boxplot with Pandas in Python
  • How can I rename a PySpark dataframe column by index? (handle duplicated column names)
  • How to calculate hash of a python class object
  • Using ideas from HashEmbeddings with sklearn's HashingVectorizer
  • keycloak.exceptions.KeycloakGetError: 404: b'' using Python 3.7
  • How to modify a column in a SQLite3?
  • VS Integration Services: flat file source to OLE DB destination - detect new data columns in file, add columns to table,
  • Customize xticks in matplotlib plot
  • How can I show the image in a labelframe which is inserted through askopenfilename?
  • Boxplot with distibution size histogram on top (and median regression)
  • Fit differential equation with scipy
  • ModuleNotFoundError: Correct setup
  • How to pass rendered plot to a html file through render_template?
  • Create flat ndarray from DataFrame column containing arrays
  • Bring radial axes labels in front of lines of polar plot matplotlib
  • Python3: Unable to split word from parsed data
  • Using Python to login to a website and web scrape
  • Customise shift in matplotlib offset
  • Combining and Reshaping rows and columns of 2 dataframes in R or Python
  • Regex condition after and before a known phrase
  • subplots based on records of two different pandas DataFrames ( with same structure) using Seaborn or Matplotlib
  • find numpy array in other numpy array
  • Print Triangle Pyramid pattern using for loop python
  • Python Script Running through Command Line Not Creating CSV
  • Questions about Subclassing
  • Creating list with dictionary instead of multiple dictionaries in python
  • Sorting queryset results in a template
  • Django Rest Framework allow not authenticated access to a view in certain cases
  • How do I efficiently map integers to URIs in a multidemnsional array?
  • Installing Python packages for Visual Studio Code
  • How to merge two columns into one in pandas dataframe
  • Decompose string of different symbols in python
  • pandas merge and group concat
  • How to traverse tree for making binary code from a HuffmanTree?
  • Check if IP is in network on Python3
  • non equally spaced points along x-axis in a plot
  • Concatenation of text files consisting list of lists?
  • Use regex to parse characters on a line of text
  • pandas df.fillna - filling NaNs after outer join with correct values
  • How can I undo a time series conversion of a pandas dataframe?
  • Virtual environment is not working in Django
  • FileNotFoundError in Python during Arabic text analysis
  • How to read email using python and smtplib
  • How to write a function which takes a string and turns into a single digit?
  • Linear Regression without Least Squares in sklearn
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org