import pandas as pd
from sklearn.utils import shuffle
df = pd.read_excel(ori_path,sheet_name=0)
df = shuffle(df)
df.to_excel(ori_path, encoding='utf8', index=None)
简单有效,相信我
本文介绍了如何使用pandas库简单地对Excel文件进行随机打乱,提高数据预处理的灵活性。通过shuffle函数,代码实现轻量且高效,适用于数据科学中的初步数据整理工作。
import pandas as pd
from sklearn.utils import shuffle
df = pd.read_excel(ori_path,sheet_name=0)
df = shuffle(df)
df.to_excel(ori_path, encoding='utf8', index=None)
简单有效,相信我
1428
28万+

被折叠的 条评论
为什么被折叠?