对象没有属性

时间:2021-05-13 15:12:54

标签: python pandas numpy

我正在学习 python/numpy。我遵循了说明,但有些代码不起作用。

    import numpy
    import os
    desktop = os.path.normpath(os.path.expanduser("~/Desktop"))
    import pandas
    x = pandas.read_csv('Desktop/numpy exc/2dcsv.csv',header = None)
    print(type(x))
    print(x.info)
    y = x.as_matrix()
    print(y)

AttributeError: 'DataFrame' 对象没有属性 'as_matrix'

2 个答案:

答案 0 :(得分:4)

不要尝试x.to_numpy(),而是尝试Deprecated since version 0.23.0: Use DataFrame.values() instead.

在熊猫的文档中它说:

public class User
{
    [Required]
    public int ID { get; set; }

    [Required, 
        StringLength(20, MinimumLength = 2, 
        ErrorMessage ="Name has to be between 2 and 20 characters long")]
    public string Name { get; set; }

    [Required, 
        DataType(DataType.EmailAddress), 
        RegularExpression(@"^[\w!#$%&'*+\-/=?\^_`{|}~]+(\.[\w!#$%&'*+\-/=?\^_`{|}~]+)*"+ "@"+ @"((([\-\w]+\.)+[a-zA-Z]{2,4})|(([0-9]{1,3}\.){3}[0-9]{1,3}))$",
        ErrorMessage = "Invalid Email Format")]
    public string Email { get; set; }
    

    [Required, 
        DataType(DataType.Date), 
        Display(Name = "Date Of Birth")] 
    public DateTime DateOfBirth { get; set; }

    [Display(Name = "Additional Info"), 
        DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", 
        ApplyFormatInEditMode = true)]
    public string AdditionalInfo { get; set; }

    [Required, 
        StringLength(24, MinimumLength = 8, 
        ErrorMessage = "Password has to be between 8 and 24 characters long"), 
        DataType(DataType.Password)]
    public string Password { get; set; }

}

答案 1 :(得分:3)

相关问题