I create a DataFrame and set an index. If I append a row via append then the index is lost.
import pandas as pd
history = {}
history_cols = {
"event_time": "E",
"close": "c",
"base_volume": "v",
"quote_volume": "q",
"total_number_of_trades": "n"
}
ticks = [
{'event_time': 1638470651223, 'close': '133.41000000', 'base_volume': '70094.70000000', 'quote_volume': '9415851.87690000', 'total_number_of_trades': 30917},
{'event_time': 1638470652088, 'close': '133.41000000', 'base_volume': '70094.70000000', 'quote_volume': '9415851.87690000', 'total_number_of_trades': 30917},
{'event_time': 1638470653224, 'close': '133.41000000', 'base_volume': '70094.70000000', 'quote_volume': '9415851.87690000', 'total_number_of_trades': 30917},
{'event_time': 1638470654189, 'close': '133.41000000', 'base_volume': '70094.70000000', 'quote_volume': '9415851.87690000', 'total_number_of_trades': 30917},
{'event_time': 1638470655203, 'close': '133.41000000', 'base_volume': '70094.70000000', 'quote_volume': '9415851.87690000', 'total_number_of_trades': 30917},
{'event_time': 1638470656201, 'close': '133.41000000', 'base_volume': '70094.70000000', 'quote_volume': '9415851.87690000', 'total_number_of_trades': 30917}
]
history["AXSBUSD"] = pd.DataFrame(columns=history_cols.keys())
history["AXSBUSD"].set_index("event_time", inplace=True)
history["AXSBUSD"]
The empty DataFrame has the index:
close base_volume quote_volume total_number_of_trades
event_time
Now I append a row with a dict ...
history["AXSBUSD"] = history["AXSBUSD"].append(ticks[0], ignore_index=True)
history["AXSBUSD"]
... and this is the result:
close base_volume quote_volume total_number_of_trades event_time
0 133.41000000 70094.70000000 9415851.87690000 30917 1.638471e+12
Has anyone an idea why the index is gone?