Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Series' object has no attribute 'applymap'

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()
like image 428
DarknessPlusPlus Avatar asked Mar 10 '18 14:03

DarknessPlusPlus


People also ask

What does Applymap do in pandas?

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.

What is the difference between apply and Applymap?

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.

Is Applymap slow?

ApplyMap() is usually slower, JOIN uses more resources. If you are not handling hundreds of millions of rows, then it probably doesn't matter.


1 Answers

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)
like image 62
Espoir Murhabazi Avatar answered Oct 14 '22 09:10

Espoir Murhabazi