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 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类