It looks like you're new here. If you want to get involved, click one of these buttons!
def data_from_sql(): # fetch all query
try:
db = pymysql.connect(host, user, password, database)
cursor = db.cursor()
sql_query_2 = "SELECT * FROM tick_data.ticks WHERE date >= NOW() - INTERVAL 5 MINUTE"
cursor.execute(sql_query_2)
records = cursor.fetchall()
cursor.close()
print("Total rows are: ", len(records))
df = pd.DataFrame(records, columns=['token', 'last_price', 'time']).set_index('time')
ohlc = df.groupby('token').resample('5min')['last_price'].ohlc()
excel_details(ohlc) # send the data to other function for updating my excel sheet.
except pymysql.Error as error:
print("Failed to read data from table", error)
data_from_sql()
while True:
data_from_sql() # for infinite loop
Ok now the output of the above code is:
new_close = ohlc.iloc[-2]['close']
print(new_close)
And , for this i'm getting the "close_price of only my last token no "3861249":
292.05
But i need close_price of all the token number , so please help me out on how to get the desired result.
List comprehensions example
result = [(x, y,z) for x, y,z in zip(df['column1'], df['column2'],df['column3'])]