Convert datetime to float variable
How does one convert from variable c:
c = datetime.now() datetime.datetime(2018, 1, 13, 18, 4, 44, 76286)
The hours, minutes and seconds to the following float variable:
And how can this be reversed as well?
See also questions close to this topic
How to append a integer iteration into a string in python?
So this is my problem:
first I iterate
for i in range(1,21): print (i)
then I have a variable basename="Station"
I want a result where the output is Station_1.txt, Station_2.txt etc.
I managed to add the "_" to the variable basename like
mylist1 = ("_") s = (basename) for item in mylist1: s += item
but now I have the problem on how to get the iteration on top of the variable basename, I could get is as it own like "Station_, 1, Station_, 2" but not inside the string itself.
Sorry, a total beginner here :)
Python: number of words in line
I have a file with a lot of lines. I need to count the number of words only in line 35. Is there an easy way to do so?
"'ReverseManyToOneDescriptor' object has no attribute 'all'"
I found the answer myself, but thought that the question might benefit others:
i got the following error whenever i called:
Error: "'ReverseManyToOneDescriptor' object has no attribute 'all'"
class Schema(models.Model): label = models.TextField() description = models.TextField() url = models.URLField(unique=True) def __str__(self): return self.label class Meta: app_label = 'metadata' class Object(models.Model): label = models.TextField() description = models.TextField() # related name should not be objects, because that will cause problems schema = models.ForeignKey( Schema, related_name='objects', on_delete=models.CASCADE) def __str__(self): return "%s.%s" % (self.schema.label, self.label) class Meta: app_label = 'metadata'
Accumulate date ranges
I recieve as input a list of date ranges. Some of them are overlapping, some are adjacent. Is there any collection that would accumulate the incoming date ranges?
(2018/01/01, 2018/01/02), (2018/02/15, 2018/03/21), (2018/01/10, 2018/01/10), (2018/01/03, 2018/01/09)
(2018/01/01, 2018/01/10), // 1st, 3rd, 4th lines combined (2018/02/15, 2018/03/21) // 2nd line
Why does pandas dataframe tolist return datetime as values
So I have this pandas dataframe I want to save in a postgres database.I want to keep the datetime as timestamp with timezone.
df.set_index(['datetime', 'area_id'], inplace=True) df = df.tz_localize('Asia/Tokyo', level=0) df.reset_index(inplace=True) print(df.values)
And I get
[Timestamp('2018-04-01 00:00:00+0900', tz='Asia/Tokyo') 1 1 3000.0]
however when I do this the dataframe become values even though I want the datetime. What I want [('2018-04-01 00:00:00+0900',1, 1, 3000.0)]
However when I ran this code
d = list(zip(*[df[c].values.tolist() for c in df]) print(d)
I get values in stead of datetime.
(1522508400000000000, 1, 1, 3000.0)
what I have tried so far.
but it didn't work. I found this solution Pandas DataFrame Date Series to List conversion but it wasn't helpful in my case. It shows only one particular columns while I want to do it for all the columns.
I have an issue in my Laravel application.
console.log(expDate + ' --> ' + new Date(expDate).getTime() + " --> " + $.now());
It's output in Firefox:
09/25/18 4:31 PM UTC --> 1537893060000 --> 1537875054235
Output in IE:
09/25/18 4:31 PM UTC --> -1617866940000 --> 1537875062939
Can anyone help me with how to resolve the issue.
I want it so the
new Date(expDate).getTime()gives the correct time in all browsers.
Any help will be appreciated.