46 questions
0
votes
1
answer
40
views
Using Value from Another Function in Pandas .Applymap()
Is it possible to color code DataFrame cell values based on its value compared to the value returned from another function.
Here is an example of the DataFrame coloring that I created using the ...
0
votes
2
answers
69
views
What and why following two with same apply() functionality differ in their results?
Objective is to convert each string to uppercase in Pandas dataframe (df).
Used following 3 approaches but not sure why 1st is NOT working ?
Please refer code snippet and 3 dataframes viz df1, df2, ...
1
vote
2
answers
231
views
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(
...
0
votes
3
answers
1k
views
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 ...
1
vote
1
answer
1k
views
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 ...
1
vote
1
answer
244
views
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]...
2
votes
3
answers
1k
views
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'],}, ...
0
votes
0
answers
315
views
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 ...
0
votes
1
answer
145
views
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
votes
1
answer
269
views
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 ...
1
vote
1
answer
810
views
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:
...
1
vote
1
answer
276
views
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 ...
0
votes
1
answer
794
views
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 ...
1
vote
1
answer
309
views
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 ...
0
votes
2
answers
182
views
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. ...
0
votes
2
answers
1k
views
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 :
a
b
c
d
1--2
3
4
None
2
34--32
12
None
23
123--...
1
vote
2
answers
2k
views
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 ...
-2
votes
1
answer
1k
views
Remove NaN from lists in Pandas dataframe [duplicate]
I have a dataframe whose values are lists which contains 'nan'. Is there an easy and pythonic way to remove those 'nan' values from lists within the dataframe? I have defined a function which returns ...
0
votes
1
answer
89
views
Why apply function did not work on pandas dataframe
ct_data['IM NO'] = ct_data['IM NO'].apply(lambda x: pyffx.Integer(b'dkrya@Jppl1994', length=20).encrypt(int(x)))
I am trying to encyrpt here is below head of ct_data
Unnamed: 0 IM NO ...
1
vote
1
answer
504
views
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 ...
2
votes
2
answers
2k
views
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 ...
-1
votes
1
answer
354
views
Python replace NaN values of a field holding numeric values with empty and not single quotes which will be treated later as strings
I am uploading some data frames into snowflake cloud. I had to use the following to transform all field values into string:
data = data.applymap(str)
The only reason I am doing that is that without ...
0
votes
1
answer
929
views
Python - Pandas - Style.ApplyMap working strange
Can anybody help me out with the following strange scenario?
So I have the following Table ( Oracle ) which looks like as follows:
Screenshot
Going back to python, I have created the following Script. ...
1
vote
2
answers
2k
views
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 ...
0
votes
1
answer
749
views
Apply Function for Text Cleaning to Multiple Columns
I have three columns of text in my dataframe that I want to apply the same function to. Here is what I have tried below. What should I pass as a parameter to my function?
def clean_columns():
...
0
votes
1
answer
49
views
Modifying an indexed DataFrame inside a function changes the original variable
The following script prints the same input variable input_df twice at the end - before and after df_lower has been called:
import pandas as pd
def df_lower(df):
cols = ['col_1']
df[cols] = ...
0
votes
2
answers
53
views
Why doesn't the clean-up persist?
I clean a csv table. I want to delete symbols in the ID. It looks like this:
ID Address
"(2 Hamburg
"(3 Cologne
"(4 Berlin
"(5 ...
I want to delete the "(
The code I used
Ost.applymap(...
0
votes
1
answer
1k
views
Count and map number of appearances of strings
I am mapping specific keywords with text data using applymap in Python. Let's say I want to check how often the keyword "hello" matches with the text data over all rows. Applymap gives me the desired ...
1
vote
1
answer
963
views
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 ...
0
votes
2
answers
244
views
Get the maximum length of a word from a paragraph
I am working on a text problem where I have my pandas dataframe holding many columns out of which one consists of paragraphs. What I need in output are 3 columns as defined -
Length of largest words
...
1
vote
2
answers
67
views
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'...
0
votes
1
answer
3k
views
call multiple argument function in applymap in python
I wrote a function for giving colors to the variables for pandas data frame.
there I used two arguments first one is variables list and another is threshold values list(i'am having only two values in ...
1
vote
1
answer
2k
views
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 ...
-2
votes
1
answer
188
views
Apply function in python (dataframe)
I read that the apply function takes the entire series as the input and apply the custom function to that series. However I applied the below function to a col in a dataframe and it worked as if It ...
0
votes
0
answers
134
views
Using a formatter function with pandas.DataFrame.applymap has no effect
I have the following CSV file, that I want to read and reformat with pandas:
10,1.89e-3,1.92e-3,2.14e-3,2.23e-3,2.38e-3,2.43e-3,2.33e-3,2.87e-3
10,1.84,2.01,2.03,1.99,2.11,2.11,2.09,1.95
20,5.28e-4,...
2
votes
1
answer
5k
views
TypeError: Unsupported type <class 'numpy.dtype'> 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"...
2
votes
1
answer
85
views
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, ...
1
vote
1
answer
223
views
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 ...
-1
votes
1
answer
679
views
Python: Apply function to certain elements/cells in pandas dataframe
I Have the following table in Pandas.
+--------+--------+--------+-----+
| A | B | C | D |
+--------+--------+--------+-----+
| foo | b'bar0 | b'foo0 | 253 |
| b'bar0 | bar | ...
1
vote
1
answer
2k
views
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-...
2
votes
2
answers
1k
views
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-...
1
vote
1
answer
342
views
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 ...
0
votes
2
answers
595
views
How to use applymap in python pandas dataframe to handle scale for normalization
Firstly, i apologize for a vague question . Let me explain.
I have a pandas dataframe containing 2 columns namely square feet and number of bedrooms. I am trying to compute the price using linear ...
2
votes
1
answer
4k
views
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 ...
2
votes
1
answer
378
views
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 ...
6
votes
2
answers
4k
views
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....