I am trying to use applymap to my dataset to create floats into integers. But I get the "'Series' object has no attribute 'applymap'" error.
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()
The applymap() function is used to apply a function to a Dataframe elementwise. This method applies a function that accepts and returns a scalar to every element of a DataFrame. Python function, returns a single value from a single value.
apply() is used to apply a function along an axis of the DataFrame or on values of Series. applymap() is used to apply a function to a DataFrame elementwise. map() is used to substitute each value in a Series with another value.
ApplyMap() is usually slower, JOIN uses more resources. If you are not handling hundreds of millions of rows, then it probably doesn't matter.
As said in the documentation applymap apply a function to a whole Dataframe not to a series
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
To apply for function to a series use map or in your case just astype (np.float) could also work.
If you want to cast the column to float do this :
self.file['Value'].astype(np.float32)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With