grouping pandas datafreme columns according to only time

44 views Asked by At

I have a dataframe including datatime and numeric data. I want to count "NET" between each hours. For example 09:00-10:00- Sayi=4.
But I don't want to see date. I want to leave only time. How can I do? My code this (Note: photo has been cropped. Data is much) enter image description here

import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime as dt

df = pd.read_excel(r"C:\Users\cem.aydemir\Documents\PYTHON\Ocak_Nakliye.xlsx")
df['Sayi'] = df['NET']
df = df[['Zaman' , 'Sayi']]
df['Zaman'] = pd.to_datetime(df['Zaman'], 
                                    format='%H:%M:%S')
df['Zaman'] = (df.Zaman - df.Zaman.dt.normalize()).dt.floor('5T')

df = df.groupby([pd.Grouper(key= 'Zaman', 
                               freq= 'h')])['Sayi'].count().reset_index()
df = df[df['Sayi'] > 0]
x =df['Zaman']
y= df['Sayi']
plt.figure(figsize=(15,8))
plt.plot(x,y)
plt.show()
pd.options.display.min_rows = 20
print(df)

And output: Zaman Sayi 0 0 days 00:00:00 4 8 0 days 08:00:00 142 9 0 days 09:00:00 2600 10 0 days 10:00:00 3997 11 0 days 11:00:00 3345 12 0 days 12:00:00 3217 13 0 days 13:00:00 1395 14 0 days 14:00:00 2203 15 0 days 15:00:00 2913 16 0 days 16:00:00 3869 17 0 days 17:00:00 3655 18 0 days 18:00:00 1893 19 0 days 19:00:00 218 20 0 days 20:00:00 37 21 0 days 21:00:00 12 22 0 days 22:00:00 9 23 0 days 23:00:00 1

I try to gruopby according to hours. But Python is groping wiht date. So, I try to leave only time. But Python output "0 days" with time. I want to see only time and I can not do it.

0

There are 0 answers