【问题标题】:How to create a data frame from a text file [closed]如何从文本文件创建数据框 [关闭]
【发布时间】:2020-07-02 03:41:23
【问题描述】:

我无法使用以下数据创建数据框:

Force (N)   microstrain1    microstrain2    microstrain3    microstrain4    microstrain5
24.838      9.689       -20.299     19.785      15.601      -7.681
49.691      22.610      -40.797     41.304      32.200      -15.332
75.309      33.357      -61.678     62.512      48.726      -22.422
97.227      41.944      -80.524     81.011      62.266      -30.228
121.641     52.692      -100.775    100.703     77.248      -36.884

每次我尝试使用分隔符时,都会收到以下消息:

/Users/macbookpro/PycharmProjects/Projects/Lab_3/Bending.py:5: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support regex separators (separators > 1 char and different from '\s+' are interpreted as regex); you can avoid this warning by specifying engine='python'.
  df1 = pd.read_csv('MEE322-thurs_1040_group1_9.5cm.txt',delimiter='  ')

【问题讨论】:

  • 欢迎来到 SO!当询问调试问题时,我们需要在问题本身中演示问题的最小代码。没有它,我们只能猜测您写的内容,这在提供建议或答案时几乎没有帮助。见“MCVE

标签: dataframe


【解决方案1】:

你试过python引擎而不是c引擎吗?:

df1 = pd.read_csv('MEE322-thurs_1040_group1_9.5cm.txt', delimiter=' ', engine='python')

【讨论】:

  • 谢谢你成功了!我从windows换成mac,从来没有出现过这个问题,请问有什么原因吗?
  • 这可能会回答:stackoverflow.com/questions/52774459/… 我认为这归结为 c 选项更快,但 python 选项支持更多的东西。
猜你喜欢
  • 2021-12-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-10
  • 1970-01-01
  • 2020-03-01
  • 2019-05-16
  • 1970-01-01
相关资源
最近更新 更多