[Python] Inquiries on how to prevent it from appearing as scientific notation

Asked 2 years ago, Updated 2 years ago, 44 views

There is a Pandas data frame, and one column is timestamp.
The value is expressed as 1518586207202 I want to represent this divided by 1000 as an integer.

So if you try df1.timestamp/1000
This is 1.518586e+09. It's expressed like this Is there a way to express this in an integer?

jupyter notebook in use.
It's no use trying np.set_printoptions(suppress=True).

numpy pandas scientificnotation

2022-09-21 20:19

1 Answers

Wouldn't it be better to add a new column in the data frame that represents an integer value?

The simplest way is to utilize the // operator. This operator returns only the quotient (integer value) that discarded the remainder in the division. For example, the value of 7//3 is 2, and 5//2 is 2.

ts  = 1518586207202
sec = ts // 1000
print(ts)   # result: 1518586207202
print(sec)  # result: 1518586207

If you want to store the value of the sec variable as it is, and you want the output to be an integer, you can use string formatting as follows.

ts  = 1518586207202
sec = ts / 1000
print('{:d}'.format(sec))  # result: '1518586207'
print('%d'%(sec))          # result: '1518586207'

I hope it helps you.


2022-09-21 20:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.