matplotlib: AttributeError:‘DataFrame‘ object has no attribute ‘xx‘

matplotlib: AttributeError:‘DataFrame‘ object has no attribute ‘xx‘

画图的时候,发现bug:读取data文件发现没有相应的属性。

问题在:csv文件的数据格式不对吧,正确格式应该为:

“”,”Education”,”Income”
“1”,10,26.6588387834389
“2”,10.4013377926421,27.3064353457772
“3”,10.8428093645485,22.1324101716143
“4”,11.2441471571906,21.1698405046065
“5”,11.6454849498328,15.1926335164307
“6”,12.0869565217391,26.3989510407284
“7”,12.4882943143813,17.435306578572

属性、序号都要加引号。

读取数据的方法2(这应该是数据量小的时候):

import pandas as pd
data = pd.DataFrame({‘Education’: [10.000000, 10.401338, 10.842809, 11.244147, 11.645449, 12.086957, 12.048829, 12.889632, 13.290970, 13.732441, 14.133779, 14.635117, 14.978589, 15.377926, 15.779264, 16.220736, 16.622074, 17.023411, 17.464883, 17.866221, 18.267559, 18.709030, 19.110368, 19.511706, 19.913043, 20.354515, 20.755853, 21.167191, 21.598662, 22.000000],
‘Income’: [26.658839, 27.306435, 22.13241, 21.169841, 15.192634, 26.398951, 17.435307, 25.507885, 36.884595, 39.666109, 34.396281, 41.497994, 44.981575, 47.039595, 48.252578, 57.034251, 51.490919, 51.336621, 57.681998, 68.553714, 64.310925, 68.959009, 74.614639, 71.867195, 76.098135, 75.775216, 72.486055, 77.355021, 72.11879, 80.260571]})

Original: https://blog.csdn.net/jiazihuangtian/article/details/125562202
Author: 城府1805
Title: matplotlib: AttributeError:‘DataFrame‘ object has no attribute ‘xx‘

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/764352/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球