gpt4 book ai didi

python - “系列”对象没有属性 'applymap'

转载 作者:行者123 更新时间:2023-12-01 15:00:25 26 4
gpt4 key购买 nike

我正在尝试对我的数据集使用 applymap 以将浮点数创建为整数。但是我收到“'Series' 对象没有属性'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()

最佳答案

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

Apply a function to a DataFrame that is intended to operate elementwise, i.e. like doing map(func, series) for each series in the DataFrame



要向系列申请功能,请使用 map或者在您的情况下只是 astype (np.float) 也可以工作。

如果要将列转换为 float ,请执行以下操作:
self.file['Value'].astype(np.float32)

关于python - “系列”对象没有属性 'applymap',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49209925/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com