import vk_api import pandas as pd import time import json vk_session = vk_api.VkApi('******', '*******') # логин и пароль vk_session.auth() vk = vk_session.get_api() def main(): count_in = vk.groups.getMembers(group_id='******') count = count_in['count'] print(count) offset = 0 i = 0 step = 1000 for count in range(count_in['count'], 0, -step): y = vk.groups.getMembers(group_id='******', offset=i * step,fields='contacts') time.sleep(3) data = y df = pd.io.json.json_normalize(data['items']) df.to_csv(r'********.csv', index=False, mode='a', header=(i == 0), encoding='utf8') i += 1 if __name__ == '__main__': main() The fact is that when I open the downloaded csv in Linux, there is no problem, but if it is Windows or Mac OS, then I have problems with the encoding. If I do df.to_excel , then an error occurs that the excel module does not have the keyword mode.
What is this parameter generally responsible for? And is there its equivalent for Excel? How best to solve this problem? Write a converter separately? If so, how can this be implemented for a large number of CSV files? Or can export directly to Excel xlsx file? And how is this implemented?
The fact is that as the loop iterates, the data should be written to the file, and not overwritten.
modeis the mode for opening the file'********.csv'. Ifmode='w', then the file will be overwritten by new data, if'a', new data will be added to the end of the file (there are other mode values) - gil9red