简体   繁体   中英

How can I use plot a box with data type datetime with panda

#Convert data type to continuous for these columns
for column in continuous_columns:
    df[column] = df[column].astype('datetime64')
cdc_case_earliest_dt       datetime64[ns]
cdc_report_dt              datetime64[ns]
pos_spec_dt                datetime64[ns]
onset_dt                   datetime64[ns]
continuous_columns = df.select_dtypes(['datetime64']).columns 

# Plot a histogram summary sheet of the continuous features and save in a png file
df[continuous_columns].hist(layout=(6, 4), figsize=(30,30), bins=10)
plt.savefig('continuous_histograms_1-1.pdf')

for col in continuous_columns:
        f = df[col].plot(kind='box', figsize=(10,5), bins=10)
        plt.title(col)
        plt.ylabel('number of entries')
        plt.show()   

My question is how can plot the box graph with data type datetime? It works for histogram df[continuous_columns].hist but fail in df[col].plot saying no numeric value. I know it is related to data type but I am not sure how to change that it seem .hist can accept datetime as input but not plot. Can somebody know the solution?

for .plot method, it seems it cannot take the datetime datatype as input. What I did is convert it to int first.

df_unix_sec = df['cdc_case_earliest_dt'].astype(int)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM