I have data on 5 runners for 1 week; start time and end time in a race. I want to graph how long it took each runner to finish the race
when I subtract the cells for start and end time, I get a result as 3:00 AM instead of 3 hours. I think this is why I'm having an issue creating a stacked column chart
how can I subtract 2 timestamps and get it to spit out just the hours instead of another time stamp?
I want the date on x axis and time to complete the race on y axis
thank you
here is a sample of the data
https://imgur.com/xRyDynl
i want a stacked column chart that has dates on the x axis. so 1/1 will have 1 bar that has 30 mins for racer 1, 35mins for 2, and 40 mins for 3
Related
I have a pandas dataframe of about 3 years with the resolution of 6 seconds and I want to group the data into 24-hour bins and plot each day using matplotlib in a loop.
This is my dataframe's head:
timestamp consumption
0 2012-11-11 12:00:03 468
1 2012-11-11 12:00:09 476
2 2012-11-11 12:00:16 463
3 2012-11-11 12:00:22 449
4 2012-11-11 12:00:28 449
It includes the power consumption of a house from 2012 till 2015. After the pre-processing, the dataframe starts at about 12 pm of the first day. I need to plot all of the dataframe in 24-hour intervals and each plot must represent for a single day that starts from about 12 pm and ends at about 12 pm of the next day
So, I need about 1500 plots that show the power consumption of each day starting from 12 pm, for about 1500 days of my dataframe.
Thanks in advance.
Update: The reason I want to plot 1500 days separately, is I want to check each night's power consumption and label the occupant's sleep pattern. And I considered each day from 12 pm to 12 pm to have a complete sleep cycle in one plot. And after preparing the labels I'll be able to use them as train and test data for classification
Consider this not only an answer but also a suggestion. First, convert the column 'timestamp' into the index (DatetimeIndex)
df.set_index(df['timestamp'], inplace=True, drop=True)
Then, get all the unique days that happen in your DataFrame
unique_days = list(set(df.index.to_period('D').strftime('%Y-%m-%d')))
We then squeeze the DataFrame into a Series
del df['timestamp']
df = df.squeeze()
Now, just plot unique days in your series in separate subplots.
import matplotlib.pyplot as plt
unique_days = list(set(df.index.to_period('D').strftime('%Y-%m-%d')))
fig, axes = plt.subplots(nrows=len(unique_days), ncols=1)
row = 0
for day in unique_days:
df[day].plot(ax=axes[row], figsize=(50,10))
row += 1
plt.show()
Now, it's time for you to play around with the parameters of plots so that you can customize them to your needs.
This is kind of a strange request. If we knew what your end objective is, it might be easier to understand, but I'm going to assume you want to plot and then save figures for each of the days.
df['day'] = (df['timestamp'] + pd.Timedelta('12h')).dt.date
for day in df['day'].unique():
mask = (df['day'] == day)
#<the code for the plot that you want>
plt.plot(x=df[mask]['timestamp'].dt.time,y=df[mask]['consumption'])
plt.savefig('filename'+str(day)+'.png')
plt.close()
I need to check if a time of collection is within allowed time window or not.
For e.g.
A B C
1 10.36 10.30 1 min out of +/- 5 minutes window
2 10.24 10.30 1 min out of +/- 5 minutes window
A1 here time of collection of data, and B1 is the scheduled time. The acceptable window or range for this is +/- 5 minutes out of window. In this case the time of collection is 1 min out of +/- 5 minutes window. Similar example is shown in row 2. How can i get C1 to show the message as above which can account for + 5 minutes and - 5 minutes scenarios?.
Thanks in advance.
=IF(ABS(A1-B1)>(5/1440),"Problem!","OK")
5/1440 is 5 minutes (1440 minutes in a full day)
Use this formula¹ in C1 and fill down as necessary,
=ROUND(MAX((ABS(A1-B1)-0.05)*100, 0), 0)
Use the following custom number format on column C,
0 \mi\n out of ± 5 \mi\nut\e wi\n\dow
The advantages of a custom number format is that the numbers remain numbers and are available for future calculations (e.g. SUM, AVERAGE, etc) while displaying the text you wish to show. Note the right-alignment in the cells indicating true numbers.
¹ This formula depends on the time values being mixed numbers and not true time. If the time values are true time with a non-EN-US number format then additional maths may have to be applied to the formula.
I have done 24 hour measurement and results obtain contains around 1400 entries. Now I want to plot those results in such a way
That x axis represent my time and y axis the corresponding value.
My x axis should be divided into 24 sections each representing 1
hour.
My exact start time is 14:00 and end time is next day 14:00.
For more clarification I am adding a simple version of my data here below
And resulting Plot I am getting is this.
I look forward to your answers. Thank you.
If the time values go across midnight, you need to add a date part to the time value, so they can be plotted correctly as before and after midnight. At the very least, the time values for the first day should have a 0 before the decimal, e.g. 0.875 for 9 pm, and the values after midnight should have a 1 before the decimal, e.g. 1.125 for 1 am, so it falls on the next day and not the same day as the 9pm value.
Then plot an XY Scatter chart.
Work out what Excel's internal number (date/time value showing in General format) is for the desired X axis minimum, maximum and major/minor increments and format the x axis accordingly. Set the number format to hh:mm
Edit: For example: you want the minimum X axis value to be 24-Dec-2015 11 pm. Write that into a cell as a date/time. Format the cell to General. Then use the number you see in the format dialog for the X axis minimum.
If you want the major unit to be 1 hour, write the time value 1:00 into a cell and format it with general. Use that number in the dialog for Major.
Format the X axis labels to show time values, not dates.
greeting for every one,
I have data in excel file and i want to draw a plot in Matlab in which the Y axis represent the time with starting time in 10:45 for 24 hours i.e, from 10:00 am to the next day in 10:00 am. The x-axis represents the excel file data( the values of frequencies during 24 hours)
how to put the different times in the y axis showing the values of time in the formula of time(00:00 am/pm) using matlab?
if i use this code: ylim(subplot2,[1 24]) and xlim(subplot2,[170 230]) it will be plotted but the y-axis shows only the hours from 1 to 24 hours and i need the y-axis from 10:45 am(starting time) to(10:45)am in interval 24 hours
You can create custom tick labels by specifying tick strings with the command:
time_cells = {'10:45','11:45',...,'9:45','10:45'};
set(gca, 'YTickLabel', time_cells)
Where gca is the handle of your current plot (axes), and the time_cells is a cell array containing all your required tick labels (without the ellipse). It is probably easiest to generate this using a for-loop to create the numbers you want, and then num2str to convert to the strings you need.
I have a set of points as time of day like
05:36:37
06:31:41
06:38:24
06:39:42
07:03:47
07:04:18
07:09:28
07:28:40
07:29:20
07:29:49
07:31:57
.....
Now i would like to plot this for an entire 24 hour range in a day.
Basically x axis is the 24 hour range and i need a point for every above time on the y axis. ofcourse y axis may not vary, but i am loooking at finding the coverage as to, in a day, when did the even occur more times. Its the same event. If there are better ways to represent you can also suggest that.
Let's say your data is from A1 to A_N.
in column B enter =HOUR(A1)
in column C enter =MINUTE(A1)
Then Insert -> XY Scatter Chart