the below python program shows current datetime according to timezone in a DataFrame. The only problem is, the column names are unnecessarily appearing after every new row of data. Please refer to the image below to see the output
What else do I need to add in this program?
import time
import pandas as pd
from datetime import datetime
import pytz
while (True):
IST = pytz.timezone('Asia/Kolkata')
datetime_ist = datetime.now(IST)
Datetime=datetime_ist.strftime('%Y/%m/%d %H:%M:%S')
df= pd.DataFrame([Datetime])
df.columns = ['Datetime']
display(df)
time.sleep(1)
CodePudding user response:
The problem is how you are showing the DataFrame
.
If you want only the data in the df
you should use at
like this:
df.at[0, 'Datetime']
CodePudding user response:
This is because every new "row" in your case is an entirely new DataFrame
. What else could you ever expect?
You can't really build and display a DataFrame incrementally like this in Jupyter. Unfortunately I don't think there is any option to turn off displaying column headers without manually writing some HTML formatting code.
In your case, it might make more sense to just print()
the output you need.