logo
down
shadow

Datetime conversion - How to extract the inferred format?


Datetime conversion - How to extract the inferred format?

By : BOBO KIM
Date : November 23 2020, 03:01 PM
I think the issue was by ths following , I don't think it's possible to do this in full generality in pandas.
As mentioned in other comments and answers, the internal function _guess_datetime_format is close to being what you ask for, but it has strict criteria for what constitutes a guessable format and so it will only work for a restricted class of datetime strings.
code :
>>> from pandas.core.tools.datetimes import _guess_datetime_format_for_array
>>> array = np.array(['2016-05-01T00:00:59.3+10:00'])
>>> _guess_datetime_format_for_array(array)
# returns None
>>> array = np.array(['2016-05-01T00:00:59.300000']) # six digits, no tz
>>> _guess_datetime_format_for_array(array)
'%Y-%m-%dT%H:%M:%S.%f'
from pandas._libs.tslib import _test_parse_iso8601

def is_iso8601(string):
    try:
        _test_parse_iso8601(string)
        return True
    except ValueError:
        return False
>>> is_iso8601('2016-05-01T00:00:59.3+10:00')
True


Share : facebook icon twitter icon
Format datetime conversion show default datetime

Format datetime conversion show default datetime


By : smz
Date : March 29 2020, 07:55 AM
like below fixes the issue Don't know why strtotime doesn't work here, but with Yii you can use :
http://www.yiiframework.com/doc/api/1.1/CDateFormatter http://www.yiiframework.com/doc/api/1.1/CDateTimeParser
code :
array(
  'name'=>'Appointment',
  'value'=>'Yii::app()->dateFormatter->format("EEEE d MMMM y hh:mm:ss a", CDateTimeParser::parse($data->Appointment, "yyyy-MM-dd H:mm:ss"))'
),
HSQLDB - Date Format : Incompatible data type in conversion or invalid datetime format

HSQLDB - Date Format : Incompatible data type in conversion or invalid datetime format


By : Clara
Date : March 29 2020, 07:55 AM
Any of those help Dont try to format the date. Use query with named parameters instead. Then you can use setters for all data types. See example below:
code :
String hql = "from Player player where player.creationDate = :date";
List result = session.createQuery(hql)
.setDate("date", new Date()).list();
To convert Datetime to uniform 15 minutes format and also extract Year, Month, Day, Hour columns from DateTime

To convert Datetime to uniform 15 minutes format and also extract Year, Month, Day, Hour columns from DateTime


By : user7107872
Date : March 29 2020, 07:55 AM
I wish this help you You can use dt accessor for accessing year, month, date and hour from a timestamp. You can use date_range for getting the range of dates and set frequency for 15min for a row for every 15 minutes. For the output you want you can do the following.
code :
df['DateTime'] = pd.to_datetime(df['DateTime'])
# Create a  year month, day and time dataframe
new = pd.DataFrame({"Year": df["DateTime"].dt.year, "Month": df["DateTime"].dt.month,"Day":df["DateTime"].dt.day,"Hour":df["DateTime"].dt.hour})
# Set index to datetime after concatinating both dataframes
df = pd.concat((df,new),axis=1).set_index(df['DateTime'])

#Create a time dataframe 
time_df = pd.DataFrame({"DateTime":pd.date_range(start='2011-01-01 00:00:00', end='2011-12-31 23:45:00',freq="15min"),"Code":801,"Reading":0})

#Create a data frame of year, month, day and time 
k = pd.DataFrame({"Year": time_df["DateTime"].dt.year, "Month": time_df["DateTime"].dt.month,"Day":time_df["DateTime"].dt.day,"Hour":time_df["DateTime"].dt.hour})

# Set index to datetime after concatinating both dataframes 
time_df = pd.concat((time_df,k),axis=1).set_index(time_df['DateTime'])

# Create a new dataframe concatinating previous two dataframes by specifying proper axis
orginal_df = pd.concat((df,time_df),axis=0)

# Remove the duplicates 
orginal_df = orginal_df[~orginal_df.index.duplicated(keep='first')]

#Sort the dataframe by time
orginal_df = orginal_df.sort_index()

#Reset the index
orginal_df = orginal_df.reset_index(drop=True)
       Code            DateTime  Reading  Day  Hour  Month  Year
0       801 2011-01-01 00:00:00      0.0    1     0      1  2011
1       801 2011-01-01 00:15:00      0.0    1     0      1  2011
2       801 2011-01-01 00:30:00      0.0    1     0      1  2011
3       801 2011-01-01 00:45:00      0.0    1     0      1  2011
4       801 2011-01-01 01:00:00      0.0    1     1      1  2011
5       801 2011-01-01 01:15:00      0.0    1     1      1  2011
6       801 2011-01-01 01:30:00      0.0    1     1      1  2011
.
.
.
1375   801 2011-01-15 07:45:00      0.5   15     7      1  2011
.
.
1378   801 2011-01-15 08:30:00      0.0   15     8      1  2011
.
.
35039   801 2011-12-31 23:45:00      0.0   31    23     12  2011
orginal_df[['Code','DateTime','Year','Month','Day','Hour','Reading']]
       Code            DateTime  Year  Month  Day  Hour  Reading
0       801 2011-01-01 00:00:00  2011      1    1     0      0.0
1       801 2011-01-01 00:15:00  2011      1    1     0      0.0
2       801 2011-01-01 00:30:00  2011      1    1     0      0.0
3       801 2011-01-01 00:45:00  2011      1    1     0      0.0
4       801 2011-01-01 01:00:00  2011      1    1     1      0.0
5       801 2011-01-01 01:15:00  2011      1    1     1      0.0
Datetime conversion format

Datetime conversion format


By : user3332612
Date : March 29 2020, 07:55 AM
wish of those help There is timestamps with timezones, so if convert to UTC by Timestamp.tz_convert, times are changed:
code :
date = '2018-06-22T09:38:00.000-04:00'
dt = pd.to_datetime(date).tz_convert(None)
print (dt)
2018-06-22 13:38:00
dt = pd.to_datetime(date[:-6])
print (dt)
2018-06-22 09:38:00
C# Datetime format conversion

C# Datetime format conversion


By : Logan Quin Parkinson
Date : March 29 2020, 07:55 AM
To fix this issue I have a conversion problem with datetime. I have a date string as MM/dd/yyyy. Now I need to convert it to yyyy-MM-dd. ,
I have a date string as MM/dd/yyyy
Related Posts Related Posts :
  • How to calculate each single element of a numpy array based on conditions
  • How do I change the width of Jupyter notebook's cell's left part?
  • Measure distance between lat/lon coordinates and utm coordinates
  • Installing megam for NLTK on Windows
  • filter dataframe on each value of a samn column have a specific value of another column in Panda\Python
  • Threading with pubsub throwing AssertionError: 'callableObj is not callable' in wxPython
  • Get grouped data from 2 dataframes with condition
  • How can I import all of sklearns regressors
  • How to take all elements except the first k
  • Whats wrong with my iteration list of lists from csv
  • Tensorflow Estimator API save image summary in eval mode
  • How to Pack with PyQt - how to make QFrame/Layout adapt to content
  • How do I get certain Time Range in Python
  • python doubly linked list - insertAfter node
  • Open .h5 file in Python
  • Joining a directory name with a binary file name
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org