简体   繁体   中英

Python tuple and memory

i have a strange problem.

I get some datas like this:

save_last_row = exchange.fetch_ohlcv('BTC/USD', timeframe='1m', limit=2)
save_last_row = pd.DataFrame(save_last_row[:-1],columns=['Date Time', 'Open', 'High', 'Low', 'Close', 'Volume'])

The data looks like that:

       Date Time     Open     High      Low    Close       Volume
0  1640190840000  49075.0  49085.0  49044.0  49071.0  147792.0244

It is a loop so i get the last line every loop. Strangely, when i do that after:

last_row = save_last_row
last_row = function_convert(last_row)

i obtain that for last_row:

            Date Time     Open     High      Low    Close       Volume
0 2021-12-22 17:41:00  49041.0  49073.0  49029.0  49033.0  136169.2562

We can see the date time is not in the same format. And if i printf the save_last_row (that i didn't modify), i have:

            Date Time     Open     High      Low    Close       Volume
0 2021-12-22 17:41:00  49041.0  49073.0  49029.0  49033.0  136169.2562

WHY???? Last_row get just the data from save_last_row. how the variable save_last_row could be modify???

NB: and the function_convert just modify some values:

def conversion_date(df):
  df["Date Time"] = df["Date Time"] + 3600000 # add one hour to have local time
  df["Date Time"] = (df["Date Time"].apply(parse_dates)) # convert
  return df

EDIT: the variable last_row is converted (ok), but save_last_row also,?? (and it is not ok, i didn't convert it) so why ??

EDIT2: use save_last_row.copy() thank you Chris Doyle

If I understand you correctly you want the timestamp as an integer and not as a datetime object.

Your parse_date function parses the integer timestamp to a datetime object, which is presented differently. If you don't want that conversion just leave the second line from your conversion_date function like that.

def conversion_date(df):
  df["Date Time"] = df["Date Time"] + 3600000 # add one hour to have local time
  return df

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM