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)
Answer from Espoir Murhabazi on Stack Overflow
🌐
Brainly
brainly.com › computers and technology › high school › how can i solve this error: 'dataframe' object has no attribute 'map'?
[FREE] How can I solve this error: 'dataframe' object has no attribute 'map'? - brainly.com
November 19, 2023 - To fix the error 'dataframe' object has no attribute 'map', ensure you use 'map' only on a Pandas Series, not a DataFrame. For DataFrames, use 'applymap' for element-wise operations instead.
Discussions

python - AttributeError: 'DataFrame' object has no attribute 'map' - Stack Overflow
------------------------------... /home/edamame/spark/spark-2.0.0-bin-hadoop2.6/python/pyspark/sql/dataframe.pyc in __getattr__(self, name) 842 if name not in self.columns: 843 raise AttributeError( --> 844 "'%s' object has no attribute '%s'" % (self.__class__.__name__, name)) 845 ... More on stackoverflow.com
🌐 stackoverflow.com
FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.
Hi if I use p_map on a dataframe it raises the error: AttributeError: 'DataFrame' object has no attribute 'p_map'. I guess that because map used to be for series and not dataframes. However, if I use p_applymap on the dataframe, I get my... More on github.com
🌐 github.com
0
January 16, 2024
Mapping multiple columns from one pandas data frame to another
I'm not a Pandas guy and, in fact, find it quite complex and uninituitive, so take what follows with a grain of salt. The problem you have is that DataFrames don't have a .map method but Series objects do. So, what's happening in your code to throw the error? The difference, I think, is that score['mop_'] (note the single brackets) returns a Series object, whereas score[['merchant_merchantid_','mop_']] (note the nested brackets) returns a DataFrame object which lacks a .map method. What can you do that might work? You could look at DataFrame.apply or DataFrame.applymap to see if they fit your use-case. Hope that helps! More on reddit.com
🌐 r/learnpython
3
3
January 13, 2023
python - 'DataFrame' object has no attribute 'map' adding more column - Stack Overflow
i try to adding new column on my dataset, but this map function get me error. How to fix this? train_df = pd.read_csv("/content/drive/My Drive/data/HumanActivity/data/train.csv") trai... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 3
10

map is a method that you can call on a pandas.Series object. This method doesn't exist on pandas.DataFrame objects.

df['new'] = df['old'].map(d)

In your code ^^^ df['old'] is returning a pandas.Dataframe object for some reason.

  • As @jezrael points out this could be due to having more than one old column in the dataframe.
  • Or perhaps your code isn't quite the same as the example you have given.

  • Either way the error is there because you are calling map() on a pandas.Dataframe object

2 of 3
4

Main problem is after selecting old column get DataFrame instead Series, so map implemented yet to Series failed.

Here should be duplicated column old, so if select one column it return all columns old in DataFrame:

df = pd.DataFrame([[1,3,8],[4,5,3]], columns=['old','old','col'])
print (df)
   old  old  col
0    1    3    8
1    4    5    3

print(df['old'])
   old  old
0    1    3
1    4    5

#dont use dict like variable, because python reserved word
df['new'] = df['old'].map(d)
print (df)

AttributeError: 'DataFrame' object has no attribute 'map'

Possible solution for deduplicated this columns:

s = df.columns.to_series()
new = s.groupby(s).cumcount().astype(str).radd('_').replace('_0','')
df.columns += new
print (df)
   old  old_1  col
0    1      3    8
1    4      5    3

Another problem should be MultiIndex in column, test it by:

mux = pd.MultiIndex.from_arrays([['old','old','col'],['a','b','c']])
df = pd.DataFrame([[1,3,8],[4,5,3]], columns=mux)
print (df)
  old    col
    a  b   c
0   1  3   8
1   4  5   3

print (df.columns)
MultiIndex(levels=[['col', 'old'], ['a', 'b', 'c']],
           codes=[[1, 1, 0], [0, 1, 2]])

And solution is flatten MultiIndex:

#python 3.6+
df.columns = [f'{a}_{b}' for a, b in df.columns]
#puthon bellow
#df.columns = ['{}_{}'.format(a,b) for a, b in df.columns]
print (df)
   old_a  old_b  col_c
0      1      3      8
1      4      5      3

Another solution is map by MultiIndex with tuple and assign to new tuple:

df[('new', 'd')] = df[('old', 'a')].map(d)
print (df)
  old    col new
    a  b   c   d
0   1  3   8   A
1   4  5   3   D

print (df.columns)
MultiIndex(levels=[['col', 'old', 'new'], ['a', 'b', 'c', 'd']],
           codes=[[1, 1, 0, 2], [0, 1, 2, 3]])
🌐
Spark By {Examples}
sparkbyexamples.com › home › hbase › attributeerror: ‘dataframe’ object has no attribute ‘map’ in pyspark
AttributeError: 'DataFrame' object has no attribute 'map' in PySpark - Spark By {Examples}
March 27, 2024 - data = [('James',3000),('Anna',4001),('Robert',6200)] df = spark.createDataFrame(data,["name","salary"]) df.show() #converts DataFrame to rdd rdd=df.rdd print(rdd.collect()) # apply map() transformation) rdd2=df.rdd.map(lambda x: [x[0],x[1]*20/100]) print(rdd2.collect()) #conver RDD to DataFrame df2=rdd2.toDF(["name","bonus"]) df2.show()
🌐
Brainly
brainly.com › computers and technology › high school › what type of error is this: 'dataframe' object has no attribute 'map'?
[FREE] What type of error is this: 'dataframe' object has no attribute 'map'? - brainly.com
November 19, 2023 - The error 'dataframe' object has no attribute 'map' typically occurs in **Python **when trying to use the 'map' function on a pandas DataFrame object. The 'map' function in pandas is used to substitute each value in a Series with another value ...
🌐
Medium
medium.com › analytics-vidhya › no-more-confusion-between-apply-map-and-applymap-f982bb98c099
No more confusion between apply(), map() and applymap() | by Sayantanee Sen | Analytics Vidhya | Medium
May 27, 2022 - df['age']=[36,34,10,8,1] df.loc[0]=df.loc[0].map(lambda x: x.upper())AttributeError: 'numpy.int64' object has no attribute 'upper' This can be fixed with a small condition though! df.loc[0]=df.loc[0].apply(lambda x: x.upper() if type(x)==str else x) Unlike apply(), map() won’t work on a dataframe even if you have all columns of the same data type. Finally applymap() operates on the entire dataframe and performs element wise operations.
🌐
GitHub
github.com › dubovikmaster › parallel-pandas › issues › 5
FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead. · Issue #5 · dubovikmaster/parallel-pandas
January 16, 2024 - FutureWarning: DataFrame.applymap has been deprecated. Use DataFrame.map instead.#5 ... AttributeError: 'DataFrame' object has no attribute 'p_map'.
Author   mirix
Find elsewhere
🌐
Data Science Learner
datasciencelearner.com › home › ‘dataframe’ object has no attribute ‘map’ ( solved )
'dataframe' object has no attribute 'map' ( Solved )
September 12, 2023 - You are getting the AttributeError 'dataframe' object has no attribute 'map' as you are applying the function using the map() function. Solve it.
🌐
Reddit
reddit.com › r/learnpython › mapping multiple columns from one pandas data frame to another
r/learnpython on Reddit: Mapping multiple columns from one pandas data frame to another
January 13, 2023 -

Mapping from one column to another such as below works fine, however the requirements have changed and now need to map two columns to the summary table, and am getting the error 'DataFrame' object has no attribute 'map'. I'm sure it is something simple like a bracket or parentheses out of place, but right now not quite sure.

score['#_%_to_Total'] = (score['Total_#_Genuine'] / score['mop_'].map(summary.set_index(['mop_'])['count_Not Fraud']))*100

#Below is the line of code giving the AttributeError
score['#_%_to_Total'] = (score['Total_#_Genuine'] / score[['merchant_merchantid_','mop_']].map(summary.set_index(['merchant_merchantid_','mop_'])['count_Not Fraud']))*100
AttributeError: 'DataFrame' object has no attribute 'map'
🌐
Brainly
brainly.com › computers and technology › high school › when will this error occur: `attributeerror: 'dataframe' object has no attribute 'map'?
[FREE] When will this error occur: `AttributeError: 'DataFrame' object has no attribute 'map'? - brainly.com
This **error **occurs when trying to use the map() function on a DataFrame object in Python's pandas library. The map() function is not supported directly on a DataFrame, but you can use the apply() **function **instead.
🌐
Delicesdumaghreb
delicesdumaghreb.ca › Trending › dataframe-object-has-no-attribute-map
Delicesdumaghreb
November 15, 2024 - The error message tells us that your code is trying to apply the map() function to a Pandas DataFrame, but this function is not directly available for DataFrames. This is because map() is designed for Series objects, which represent single columns ...
🌐
DNMTechs
dnmtechs.com › attributeerror-in-python-3-programming-dataframe-object-has-no-attribute-map
AttributeError in Python 3 Programming: DataFrame Object Has No Attribute ‘map’ – DNMTechs – Sharing and Storing Technology Knowledge
In the above example, when we try to use the ‘map’ method on the DataFrame object ‘df’, we will encounter the AttributeError stating that the DataFrame object has no attribute ‘map’. This is because the ‘map’ method is not a valid operation for a DataFrame object in pandas. To resolve this issue, you can use alternative methods such as ‘apply’ or ‘applymap’ to apply a function to the elements of a DataFrame.
🌐
GitHub
github.com › pandas-dev › pandas › issues › 52353
API: rename DataFrame.applymap -> DataFrame.map · Issue #52353 · pandas-dev/pandas
April 1, 2023 - I propose deprecating DataFrame.applymap and move its functionality to a new DataFrame.map method. The name map will better communicate that this is the DataFrame equivalent of Series.map. The curr...
Author   topper-123
🌐
HatchJS
hatchjs.com › home › how to fix attributeerror: ‘dataframe’ object has no attribute ‘map’
How to Fix AttributeError: 'DataFrame' object has no attribute 'map'
January 5, 2024 - This error occurs when you try to call the `map()` function on a `DataFrame` object. The `map()` function is used to apply a function to each element of a sequence. However, the `DataFrame` object does not have a `map()` attribute, so you cannot ...
🌐
W3Schools
w3schools.com › python › pandas › ref_df_applymap.asp
Pandas DataFrame applymap() Method
import pandas as pd def make_big(x): return x.upper() data = { "name": ["Sally","Mary","John"], "city": ["London", "Tokyo", "Madrid"] } df = pd.DataFrame(data) newdf = df.applymap(make_big) print(newdf) Try it Yourself »
🌐
Learnexams
learnexams.com › home › exams & certification › when will this error occur: `attributeerror: ‘dataframe’ object has no attribute ‘map’?
When will this error occur: `AttributeError: 'DataFrame' object has no attribute 'map'? - Learnexams
November 4, 2024 - However, if you try df.map({1: 'one', 2: 'two', 3: 'three'}), it will raise an AttributeError since df is a DataFrame and lacks a .map() attribute. If you need to apply transformations across multiple columns in a DataFrame, consider using .applymap() for element-wise transformations across all columns, or .apply() for column-wise or row-wise transformations.