I have a dataframe with two types os data format... ['Data Faturamento'] is "yyyy-dd-mm" and all the others are "yyyy-mm-dd", which brings an error while using np.busday_count().
"Data faturamento" is the only column with this format...
Whats the easist way to format it? I have tried this, and it's not working.
dataFaturamento = pd.to_datetime(baseFinal["Data Faturamento"],dayfirst=True).values.astype('datetime64[D]')
0 2022-08-01 14:04:00
1 2022-08-01 14:04:00
2 2022-08-01 10:24:00
3 2022-08-01 10:24:00
4 2022-08-01 10:23:00
...
185772 2022-06-24 09:44:00
185773 2022-06-24 09:43:00
185774 2022-06-24 09:43:00
185775 2022-06-24 10:30:00
185776 2022-06-24 10:30:00
Name: Data Faturamento, Length: 185777, dtype: datetime64[ns]
The right format I'd like to use is here:
0 2022-01-10
1 2022-01-13
2 2022-01-11
3 2022-01-11
4 2022-01-11
...
185772 2022-06-24
185773 2022-06-24
185774 2022-06-24
185775 2022-06-24
185776 2022-06-24
Name: Data Entrega, Length: 185777, dtype: datetime64[ns]
CodePudding user response:
I am not sure, this what you expecting. For sorting the Data Faturamento column, you can use
df = df.sort_values(by='Data Faturamento',ascending=True)
After for getting only the date from Data Faturamento column, you can use which format you need to compute according to your case,
df['dates'] = pd.to_datetime(df['Data Faturamento'],format = '%Y-%d-%m %H:%M:%S').dt.date
or
df['dates'] = pd.to_datetime(df['Data Faturamento'],format = '%Y-%m-%d %H:%M:%S').dt.date
Hope this will help for you.
CodePudding user response:
import library
from datetime import datetime
x = datetime(2020, 8, 15, 10, 20, 30)
print(x.strftime("%Y-%m-%d %H:%M:%S"))
We can use any other character string to get information against the time we have set:
Character Description Results
%a Day, short version Sat
%A Day, full version Saturday
%w Day in number 6
%d date in in months 15
%b Bulan, short version Aug
%B months, full version Auguts
%m months in number 08
%y year, short version 20
%Y year, full version 2020
%H hour (format 24) 10
%I hour (format 12) 10
%p time AM/PM AM
%M minute 20
%S second 30
%x Date 08/15/20
%X Time 10:20:30