'系列'对象没有属性'applymap'

时间:2018-03-10 14:01:51

标签: python python-3.x pandas

我正在尝试将applymap用于我的数据集以创建整数浮点数。但我得到“'系列'对象没有属性'applymap'”错误。

import pandas as pd
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.pyplot import pie, axis, show
from pandas import Series,DataFrame

class Dataset():
def __init__(self, input):
    self.choice = input
    self.file = 0

def read(self):
    if self.choice == ("1"):
        self.file = pd.read_csv('mycsv.csv')
        self.file.plot(kind='bar')
        print(df)

        self.file['Value'].applymap(float)

def __str__(self):
    return str(self.file)

def applymap(self):
    return self.file.applymap(float)

i = (input("Pick a DataSet= "))
df = Dataset(i)
df.read()
plt.show()

1 个答案:

答案 0 :(得分:2)

documentation applymap中所述,将函数应用于整个Dataframe而不是系列

  

将函数应用于要运行的DataFrame   元素,即喜欢为每个系列做map(func,series)   数据帧

要将函数应用于一系列使用map,或者在您的情况下,只有astype(np.float)也可以使用。

如果要将列转换为float,请执行以下操作:

self.file['Value'].astype(np.float32)