Answer the question
In order to leave comments, you need to log in
I can't pass a string to writerow, what's wrong?
Console throws TypeError: string indices must be integers when trying to pass it line by line
for i in range(j, len(property)):
k = j
write_to_csv(property[k])
k += 1
j = len(property)
def write_to_csv(property):
with open('cian_parser.csv', 'a', encoding='utf8', newline='') as file:
a_pan = csv.writer(file, delimiter=',')
for building in property:
a_pan.writerow((building['адрес'], building['площадь'], building['цена'], building['цена за м²'],
building['ссылка'], building['дата выгрузки']))
read_file = pd.read_csv(r'cian_parser.csv')
read_file.to_excel(r'cian_parser.xlsx', index=None, header=True)
Answer the question
In order to leave comments, you need to log in
Understood, the cycle was not needed.
We change
def write_to_csv(property):
with open('cian_parser.csv', 'a', encoding='utf8', newline='') as file:
#...
def write_to_csv(property):
with open('cian_parser.csv', 'w', encoding='utf8', newline='') as file:
#...
This is a nightmare ... A
pile of some unnecessary squats and curtsies. There is a feeling. that the code was written without any understanding of what and how it works.
Here it is easier to count the lines that would not need to be corrected: zero such lines.
You would give at least an example of what you have there in the property served. And then, on the coffee grounds, you have to guess which of the hundreds of errors finally made the code inoperable.
Here is some nonsense in general:
for i in range(j, len(property)):
k = j
write_to_csv(property[k])
k += 1
j = len(property)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question