'Converting datetime.time to int for use in regression model / initial scatter plot
I am looking to change a datetime.time column in a pandas dataframe to an int value that isnt a unix like time i.e. from 1970 epoch.
Example of df.head(3):
trans_date_trans_time | amt | category | city_pop | is_fraud | Time of Day |
---|---|---|---|---|---|
2019-01-01 00:00:18 | 4.97 | misc_net | 3495 | 0 | 00:00:18 |
2019-01-01 00:00:44 | 107.23 | grocery_pos | 149 | 0 | 00:00:44 |
2019-01-01 00:00:51 | 220.11 | entertainment | 4154 | 0 | 00:00:51 |
So i want the 'Time of Day' column to read like an integer that can run along an axis of a simple scatter plot against 'amt'.
When I try:
y = int(df_full_slim['Time of Day'])
plt.scatter(x, y)
plt.show()
or simply:
y = df_full_slim['Time of Day']
plt.scatter(x, y)
plt.show()
it doesnt work as it cant plot a datetime.time type on a plt.
How do I get the time in a format that will run along an axis of a plot?
Thanks in advance..
Solution 1:[1]
You can plot without conversion by calling the .plot() method of the dataframe:
df_full_slim.plot(x='Time of Day', y='amt')
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | warped |