首页 > 解决方案 > 如何从文本文件创建数据框

问题描述

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

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='  ')

标签: dataframe

解决方案


您是否尝试过python引擎而不是c引擎?:

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

推荐阅读