Home > other >  Excel split and merge TypeError: always concatenate a object of type '<class' int '
Excel split and merge TypeError: always concatenate a object of type '<class' int '

Time:09-22

Work_dir='F: \ Python_practice \ Class \ Ant_learn_python \ C15'
Splits_dir=f '{work_dir} \ Splits'

The import OS
If not OS. Path. The exists (splits_dir) :
OS. The mkdir (splits_dir)

The import pandas as pd

Df_source=pd. Read_excel (' F: \ Python_practice \ Materials \ Ant_learn_pandas \ Ant - learn - pandas - master \ course_datas \ c15_excel_split_merge \ crazyant_blog_articles_source XLSX ')

Total_row_count=df_source. Shape [0]


User_names=[' A ', 'B', 'C', 'D', 'E', 'F']
Split_size=total_row_count//len (user_names)
If total_row_count % len (user_names)!=0:
Split_size +=1


Df_subs=[]
For independence idx, user_name enumerate in (user_names) :
The begin independence idx=* split_size
End=begin + split_size
Df_subs=df_source. Iloc [begin: end]
Df_subs. Append ([independence idx, user_name, df_subs])


For independence idx, user_name, df_sub df_subs in:
File_name=f "{splits_dir}/C15_ {independence idx} _ {user_name}. XLSX"
Df_sub. To_excel (file_name, index=False)




Could you tell me why will appear this error?
  • Related