Questions tagged [python-applymap]
44 questions
1
vote
1 answer
Can't perform calculations on DataFrame values
I am trying to apply a formula to each value in a Pandas DataFrame, however, I am getting an error.
def transform_x(x):
return x/0.65
transformed = input_df.applymap(transform_x)
This returns the following…

Geodatsci
- 27
- 6
1
vote
2 answers
Group by two columns and get sum?
x1 = [{'id1': 'Africa', 'id2': 'Europe', 'v': 1},
{'id1': 'Europe', 'id2': 'North America', 'v': 5},
{'id1': 'North America', 'id2': 'Asia', 'v': 2,},
{'id1': 'North America', 'id2': 'Asia', 'v': 3}]
df = pd.DataFrame(x1)
How…

Chipmunkafy
- 566
- 2
- 5
- 17
1
vote
1 answer
Pandas applymap method with passing column name as parameter
I want to use applymap method with a little bit complex function in the dataset below.
value1 value2 value3 value4 value5 people
147 119 69 92 106 533.0
31 20 12 14 26 103.0
37 22 24 18 …

mcan
- 1,914
- 3
- 32
- 53
1
vote
1 answer
Pandas: mapping with dict using more than 1 column
I got basic DataFrame:
df = pd.DataFrame([[1, 2],[3, 4],[5, 6],[7, 8]],
index=['A','B','C','D'], columns=['X','Y'])
I would like the map function to work on columns X & Y and obtain this:
X Y Chk
A 1 2 found A
B 3 4 …

JCF
- 307
- 2
- 17
1
vote
1 answer
How to pass dataframes to a function using applymap() in pandas?
I am trying to use applymap() functionality in pandas to apply a function to a whole dataframe. I have a dataframe df (a sample of it is following):
Time 2010-08-31 2010-09-30 2010-10-31 2010-11-30 2010-12-31 2011-01-31 2011-02-28 2011-03-31…

Pankaj
- 519
- 2
- 5
- 20
1
vote
1 answer
Modifying certain pandas dataframe colums, apply changes to entire original dataframe
I read a .csv file into a pandas dataframe delta_df = pd.read_csv('SAAF_121581_67_500_s.dat',index_col=False) - I need to apply the following operation to some of the columns based on the header of the column: delta_df.iloc[0:,2:].select(lambda x:…

coolleaf
- 25
- 5
0
votes
2 answers
pd.Series.str.upper function under the df.apply() is showing me the Error. On the other hand pd.Series.min is running perfectly
When I use df.apply(pd.Series.str.upper) shows me an error -
Although df.apply(pd.Series.min) is running absolutely fine! and df.apply(lambda x: x.str.upper()) is running fine too.
df = pd.DataFrame(
{
"Name":[
"Harry","Sam",…

Shubham Bhardwaj
- 7
- 2
0
votes
3 answers
Python: How to Apply Style on Pandas Dataframe by Comparing Two Values on the Same Column but on the Different Rows?
Suppose that we have this dataframe:
Value 1
Value 2
Value 3
6
5
6
6
5
10
How to apply color if values on the same column is equals but skip the first column?
In my case, column Value 2 must be colored
I have used Pandas df.apply, but…

yunastrian
- 13
- 2
0
votes
1 answer
Pandas applymap to Style cell based on another column
DB
Policy
Snapshot Time
A-DB
PROD_BACKUP
10/17/2022 12:00:00
B-DB
PROD_BACKUP
10/16/2022 10:00:00
C-DB
NONPROD_BACKUP
10/15/2022 16:00:00
If the above data is in my dataframe, I pass snapshot time through applymap and currently it…

Nick S
- 392
- 1
- 7
0
votes
0 answers
Pandas - Change values in output of dataframe.applymap(type)
I am writing a code to compare the datatype of each value in an excel spreadsheet to a database definition spreadsheet which lists the required field/datatypes.
I am using dataframe.applymap(type) to check all of the values in the excel sheet which…

RockyFlintstone
- 11
- 1
0
votes
1 answer
Pandas - ApplyMap using corresponding cell values from two different DataFrames
I have two pandas dataframes and want to apply a function "Stat / Percentage Played". The first data frame - "Stat" looks like this:
- ----- ------- ------- ------- -------
0 Name Round 1 Round 2 Round 3 Round 4
1 Tom 10 …

RickPeck
- 165
- 2
- 14
0
votes
1 answer
Understand pandas' applymap argument
I'm trying to highlight specific columns in my dataframe using guideline from this post, https://stackoverflow.com/a/41655055/5158984.
My question is on the use of the subset argument. My guess is that it's part of the **kwargs argument. However,…

Huy Truong
- 148
- 1
- 8
0
votes
1 answer
Pandas conditional formatting: Highlighting cells in one frame that are unequal to those in another
Given two pandas dataframes df1 and df2 that have exact same schema (i.e. same index and columns, and hence equal size), I want to color just those cells in df1 that are unequal to their counterpart in df2. Any hints?
More generally, if I have a…

bigO6377
- 1,256
- 3
- 14
- 28
0
votes
2 answers
Element-wise mathematical operations in multiple pandas dataframe
I have two dataframes with similar structure like follows:
df0
No. Name PropNO PropAmt
1 XYZ - -
2 ABC 1077 34.90
3 GHI - -
Total 1077 34.90
df1
No. Name PropNO PropAmt
1 XYZ 2 0.6
2 …

abhi1610
- 721
- 13
- 28
0
votes
2 answers
what is this error and how to get rid of it. TypeError: argument of type 'NoneType' is not iterable
I have a dataframe as below.. I want to highlight the cells if the value contains delimiter "--"
I tried below code. but it throws me error…

Neel333
- 1
- 3