На самом деле я написал исходный код на Python 3.7, и он работает отлично. Но тот же самый код не работает в Python 3.13.1 или Python 3.12.4.
Ниже приведен пример того, что я делаю (я тестировал скрипт, и он работает во всех трех Python версии, но он дает ожидаемый результат только в версии 3.7):
Код: Выделить всё
import pandas as pd
import numpy as np
df = pd.read_excel("path to excelfile")
# Based on header, I read in columns from the dataframe and do stuff with them.
header = df.keys()[1:] # Yes, I want to skip the first cell in the header.
# I use header_legend to make a nice legend in my plots.
header_legend = np.array(df.keys()[1:])
for i in range(0, len(header_legend)):
header_legend[i] = header_legend[i].replace("word1_word2", "word1 word2")
print(header)
print(header_legend)
Код: Выделить всё
word_skip,word1_word2,word3_word4,word5_word6
1,10,100,1000
2,20,200,2000
3,30,300,3000
4,40,400,4000
5,50,500,5000
Почему применение замены к header_legend также изменяет header и df.keys()[1:] в Python 3.12 и 3.13?
Подробнее здесь: https://stackoverflow.com/questions/793 ... t-shouldnt
Мобильная версия