Skip to main content
The 2024 Developer Survey results are live! See the results

All Questions

Tagged with
2 votes
1 answer
36 views

Python Split and assign into new Columns

I have been worked in a dataframe with one column which has data for different calls to APIs. I need to split by "," and add new columns depends of the method's name (each API contains ...
Bruno's user avatar
  • 25
0 votes
1 answer
60 views

Conditionally replacing all values in large polars dataframe with specific string using lambda function

How would you replace all integer values in a large multi-column polars data matrix that are >9999 with a string "10K+"? I tried df.map, df.apply, and df.applymap: labels = df.map(lambda ...
Stephen Beckstrom-Sternberg's user avatar
-1 votes
1 answer
28 views

pd dataframe applymap tries to modify col names

Hello i have a dataframe containing datetime infos and i'd like too format those infos so i've used this command : df2[["month", "day", "hour", "min", "s&...
FrozzenFinger's user avatar
1 vote
2 answers
189 views

Set unique identifier for cases with correpsonding previous index / same trace

Suppose I have the following dataset: Personalnumber Category Year Month Index_ID Previous_Index_ID 1 100 2022 8 42100 1 100 2022 9 9534 42100 1 9400 2023 9 4 1 9400 2023 10 485 4 2 100 2022 1 ...
PSt's user avatar
  • 103
0 votes
5 answers
74 views

Replacing values in pands df (not Nan) with the column sum except first two cols

Update: I mixed up the axis. Thats why my question seems weired. This is the new input data: give following data: import pandas as pd data = {'Org': ['Tom', 'Kelly', 'Rick', 'Dave','Sara','Liz'], ...
hadji's user avatar
  • 97
0 votes
1 answer
28 views

Create dataframe columns from a dictionary using lambda expression

I would like to create a pyspark dataframe dynamically using lambda form a give dictionary. Below is my dictionary. cols = [ {'Technical Label':'UserID', 'Column Mapping':'UID','Technical Column':'No'}...
Alex Raj Kaliamoorthy's user avatar
1 vote
2 answers
60 views

Lambda and loc function for dataframes with multiple conditions

I've this problem in my python app. I need to add a the latest column named "ValueOverlap" (I made up this values) to my dataframe with multiple conditions and calculated result. Date Open ...
Optimvs's user avatar
  • 31
0 votes
2 answers
265 views

TypeError: 'float' object is not subscriptable - Working with Pandas dataframe

I am trying to convert string values from a column where the values look like this: $200, $6,000, etc. I want to convert these values to float and save them into a new column in my dataframe so I can ...
bigrelly's user avatar
0 votes
0 answers
30 views

Using pandas in Lambda to align data from a csv file and sending it out to email

I'm having problem with aligning the data using pandas. Below is the snippet of my code: s3_client.upload_file(csv_file_path, s3_bucket, s3_key) object = s3_client.get_object(Bucket=s3_bucket,...
hellasnia's user avatar
0 votes
0 answers
41 views

How can I implement this dataframe rolling assignment efficiently

I have a dataframe with 2 columns and I'd like to compute a sequence based on these two columns. # branch below: recent mean of df.A is significantly GREATER than long time mean if df['A'].rolling(10)....
cat's user avatar
  • 95
0 votes
1 answer
107 views

Is there a way to assign a list of values to each row of a Dataframe?

I am trying to add a new column to an existing dataframe. This new column will be a list of integer values that each row will hold. I am looping through 2 dataframes to extract some records of the 2nd ...
Kavya Nagesh's user avatar
3 votes
3 answers
74 views

Pandas dataframe with a column containing lists : how to access elements "dynamically"

In my dataframe, I have one column (Vector) containing some list of elements : import pandas as pd x1 = ['A1','B1','C1'] x2 = ['A2','B2','C2','D2'] df = pd.DataFrame([['ID_1',0,x1],...
guedj's user avatar
  • 33
2 votes
2 answers
157 views

Why does assign (lambda) sometimes reads the entire column rather each individual row when assigning values?

I have a DataFrame with a code in a column. I want to extract the first digit from said code and add to a different column so I can use it to merge it with a different DF. My code is: df_a = df_a....
ssmalcontent's user avatar
2 votes
1 answer
87 views

Change datatype of one column from string to integer in pandas [duplicate]

I have data in Opensearch index like below : Document 1: units :"10" Document 2: units :" " Document 3: units :"20" In lambda, I am using pandas for data transformation. ...
Sharayu Dhamale's user avatar
2 votes
2 answers
41 views

How to pass 3 values in lambda

Lambda functions are working perfectly: funct = (lambda a,aa,aaa: (a-aa)/aaa if aa>0 else a/aaa) print(funct(200,100,2)) what I want to do is to apply this in dataframe: df[['a','aa','aaa']] using ...
PRNCSS's user avatar
  • 23

15 30 50 per page
1
2 3 4 5
36