m0_61104322 2022-04-24 06:03 采纳率: 89.5%
浏览 50
已结题

如何把dataframe里的表格读取成csv文件


import pandas as pd
train_df = pd.DataFrame(train_samples)
train_df.head(14)

target    text    line_number    total_lines
0    OBJECTIVE    to investigate the efficacy of @ weeks of dail...    0    11
1    METHODS    a total of @ patients with primary knee oa wer...    1    11
2    METHODS    outcome measures included pain reduction and i...    2    11
3    METHODS    pain was assessed using the visual analog pain...    3    11
4    METHODS    secondary outcome measures included the wester...    4    11
5    METHODS    serum levels of interleukin @ ( il-@ ) , il-@ ...    5    11
6    RESULTS    there was a clinically relevant reduction in t...    6    11
7    RESULTS    the mean difference between treatment arms ( @...    7    11
8    RESULTS    further , there was a clinically relevant redu...    8    11
9    RESULTS    these differences remained significant at @ we...    9    11
10    RESULTS    the outcome measures in rheumatology clinical ...    10    11
11    CONCLUSIONS    low-dose oral prednisolone had both a short-te...    11    11
12    BACKGROUND    emotional eating is associated with overeating...    0    10
13    BACKGROUND    yet , empirical evidence for individual ( trai...    1    10


用dataframe打开以后,是以下这样的表格,想提取为csv文件,用了一些dataframe转csv的代码,出现了错误:


TypeError: argument of type 'method' is not iterable

请教大家该如何解决?

  • 写回答

4条回答 默认 最新

  • CSDN专家-HGJ 2022-04-24 13:45
    关注

    错误提示是方法类型的参数不可迭代。如果循环写入csv的话,可这样:
    for i,df in enumerate(dfs):
    df.to_csv(f'df{i}.csv',index=False)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 5月3日
  • 已采纳回答 4月25日
  • 创建了问题 4月24日

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分