| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 628 人关注过本帖
标题:在Excel中,在每一行数据下插入3个空行。
取消只看楼主 加入收藏
蓝色烟雨中
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2023-6-3
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
在Excel中,在每一行数据下插入3个空行。
import pandas as pd
import os

cci_path = r'D:\daimaceshi\xinceshi20230501\CCI20230501.xlsx'
save_path = r'D:\daimaceshi\xinceshi20230601'
df = pd.read_excel(cci_path, sheet_name='分析表1')
writer = pd.ExcelWriter(os.path.join(save_path, 'CCI20230601.xlsx'))
df.to_excel(writer, sheet_name='分析1', index=False)
# 新建“date3”列,复制“date”列的数据到“date3”列
df['date3'] = df['date']

# 在每一个“date”数据行后插入3个空行
for i in range(len(df)):
    for j in range(3):
        df = pd.concat([df.iloc[:i+1], pd.Series(), df.iloc[i+1:]], ignore_index=True)

        #df = pd.concat([df.iloc[:i+1], pd.Series(), df.iloc[i+1:]], ignore_index=True)
        #df = pd.concat([df, df.loc[i]], ignore_index=True)
        #inserted_rows = pd.DataFrame([{}], dtype='object')
        #cci_data = pd.concat([cci_data, inserted_rows] * 3, ignore_index=True)
        # cci_data.loc[cci_data.shape[0]] = pd.Series(dtype='object')
        # cci_data.loc[cci_data.shape[0]] = pd.Series(dtype='object')
        # cci_data.loc[cci_data.shape[0]] = pd.Series(dtype='object')
#for i in range(3):
    #new_data.loc[new_data.shape[0]] =pd.serise(dtype='object')
#cci_data = pd.concat([cci_data, new_data], axis=0, ignore_index=True)

# 将结果保存到新Excel文件中
df.to_excel(writer, sheet_name='分析1', index=False)
writer._save()
试了好几种写法,都没有办法实现“在Excel的每一行下插入3个空行”,请高手赐教。
搜索更多相关主题的帖子: 分析 插入 Excel for object 
2023-06-03 22:57
蓝色烟雨中
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2023-6-3
收藏
得分:0 
回复 2楼 sheeboard
感谢帮助!
2023-06-04 15:31
快速回复:在Excel中,在每一行数据下插入3个空行。
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.034810 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved