AttributeError: 'DataFrame' object has no attribute 'as_matrix'
出现这种错误得解决办法如下所示:
panadas 版本查看方式如下所示:
import pandas
pandas.__version__
执行代码如下所示:
base_dir = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(base_dir, 'data/fix_data_tai3.csv') train_df = pd.read_csv(file_path) train_np = train_df.as_matrix()
获取出来得csv下面得数据如下所示:
[13. 24. 35. 46. 57. 68. 79.]
[14. 25. 36. 47. 58. 69. 80.]
[15. 26. 37. 48. 59. 70. 81.]
[16. 27. 38. 49. 60. 71. 82.]
[17. 28. 39. 50. 61. 72. 83.]
[18. 29. 40. 51. 62. 73. 84.]
[19. 30. 41. 52. 63. 74. 85.]]
报错如下所示:
AttributeError: ‘DataFrame’ object has no attribute ‘as_matrix’
解决方法是,替换下面得一句代码,具体操作如下所示:
base_dir = os.path.dirname(os.path.abspath(__file__)) file_path = os.path.join(base_dir, 'data/fix_data_tai3.csv') train_df = pd.read_csv(file_path) #train_np = train_df.as_matrix() train_np = train_df.iloc[:,:].values