Questions tagged [python-applymap]
44 questions
6
votes
2 answers
Using Pandas to "applymap" with access to index/column?
What's the most effective way to solve the following pandas problem?
Here's a simplified example with some data in a data frame:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randint(0,10,size=(10, 4)),…

K. Mao
- 443
- 4
- 11
2
votes
3 answers
Pandas : Concat rows of a dataframe with same index to form custom string in pairs
Say I have a dataframe
df = pd.DataFrame({'colA' : ['ABC', 'JKL', 'STU', '123'],
'colB' : ['DEF', 'MNO', 'VWX', '456'],
'colC' : ['GHI', 'PQR', 'YZ', '789'],}, index = [0,0,1,1])
colA colB colC
0 ABC DEF …

Himanshu Poddar
- 7,112
- 10
- 47
- 93
2
votes
2 answers
Pandas: How to use applymap/apply function with arguements to a dataframe without looping
Background
Link 1 shows that apply can be applied to a Series. I want to use the apply function on a subset of a DataFrame without looping through the columns.
Example code
Creating a sample DataFrame of size 7, 7
def f_test_df(n_rows, n_cols):
…

Neeraj Hanumante
- 1,575
- 2
- 18
- 37
2
votes
1 answer
TypeError: Unsupported type in write()
So i am reading a .xlsx file and i need to check how many variables in the xlsx file belong to each datatype in pandas and finally export it to excel.
So here is the code :
sheet = pd.read_excel(r"D:\Users\850034535\AnacondaProjects\Jupyter…

explorer_x
- 149
- 3
- 11
2
votes
1 answer
How to color newly added values in a data frame with Pandas?
I'd like to highlight (or color) new values in a DataFrame that previously were NaNs.
I have 2 data frames with the same index.
One with NaNs
df_nan = pd.DataFrame(np.random.randint(10, size = (10, 10))).replace(8, np.nan)
df_nan
0 1 …

solub
- 1,291
- 17
- 40
2
votes
2 answers
Using customized function inside applymap() in pandas DataFrame
I am new to pandas. I have written a function which I want to apply to all entries in a pandas DataFrame "Monthly_mean_consump" for which a sample of data is provided below.
Time 2010-08-31 2010-09-30 2010-10-31 2010-11-30 2010-12-31…

Pankaj
- 519
- 2
- 5
- 20
2
votes
1 answer
Is it possible to do applymap using the groupby in pandas?
In a pandas Dataframe I want to applymap(somefunction) using groupby (using some column index values).
mcve_01.txt
pos index M1 M2 F1_x
16230484 141 G/G G/G G
16230491 141 C/C C/C …

everestial007
- 6,665
- 7
- 32
- 72
2
votes
1 answer
replace columns with NaN based on a string in pandas
I have the below data frame
ipdb> csv_data
country_edited sale_edited date_edited transformation_edited
0 India 403171 20090101 10
1 Bhutan 394096 20090101 20
2 …

Shiva Krishna Bavandla
- 25,548
- 75
- 193
- 313
1
vote
1 answer
How to locate the Occurrences of a Specific value in pandas Dataframe
I want to locate a specific value which can occur in multiple columns . In my case it's "False" .
I know how to search "False" in individual columns as
df.loc[df['column1']==False]
df.loc[df['column2']==False]
Is there a way to find all at once…
1
vote
1 answer
How to use applymap lambda with two conditions
I'd like to find duplicated rows in a Pandas dataframe. When I use df.duplicated() it returns the following error:
TypeError: unhashable type: 'list'
To resolve this error, I tried the following:
df2 = df[df.applymap(lambda x: x[0] if…

mOna
- 2,341
- 9
- 36
- 60
1
vote
1 answer
applymap function on a df.copy() changing the original dataframe values
I have a pandas dataframe called results that contain 2 columns, one called years containing lists of years and another called line_items containing lists of integers. I am trying to sort the list values in a copy of the original dataframe, called…

geds133
- 1,503
- 5
- 20
- 52
1
vote
1 answer
Applymap a function according another dataframe value
General problem :
I have two similar data frames (same shape, same variables but different values).
How to applymap a function on each cell of df1, according the value of the same cell from df2.
My specific problem :
How to applymap(round())…

jpetot
- 145
- 1
- 10
1
vote
2 answers
Pandas dataframe lambda function/applymap to combine multiple rows in a column and remove duplicates
How can I perform the following operations on a pandas dataframe?
combine text from one column, multiple rows into one row
remove duplicates in the "one row"
repeat 1 & 2 for multiple columns
Based on the following Stack Overflow questions and…

a11
- 3,122
- 4
- 27
- 66
1
vote
1 answer
I can't seem to update the style in a dataframe in Python
enter code hereFirst, I don't know Python but am using it for a team project. I followed a plaid quickstart tutorial. I was able to create a dataframe with the enter code heredata I got back, use it to create an html and generate a pdf from that. It…

Carole Tierney
- 23
- 4
1
vote
2 answers
How to use apply for two pandas column including lists to return index in a list in one column using the element in another column?
I have a pandas Dataframe with columns of "a" and "b". Column a has a list of values as a column value, and column "b" has a list with a single value that might appear in column "a". I want to create a new column c based on column a and b that has…

Mojgan Mazouchi
- 355
- 1
- 6
- 15