All Questions
2,828 questions
0
votes
1
answer
20
views
return self._engine.get_loc(casted_key) error when in for loop, same code runs with no error outside of the loop
I have a very simple for loop which was working last week but when I run it this week on exactly the same data it is not working... when I run the code outside of the loop it works without an error. I ...
0
votes
1
answer
105
views
Looping through a dataframe column to replace NaN values with values that aren't null:
The three columns on the left are day month, and year. I am trying to fill in NaN values in the last column which I am calling 'C'. For each week of each month there is one non-empty value in the last ...
1
vote
1
answer
99
views
Vectoring nested while statements block that detects the frequency of consecutive numbers
All,
The following function get_frequency_of_events detects the frequency of consecutive numbers, for example,
import numpy as np
aa=np.array([1,2,2,3,3,3,4,4,4,4,5,5,5,5,5])
get_frequency_of_events(...
0
votes
0
answers
27
views
Create a loop to loop through 2 dataframes and format the dataframes [duplicate]
I am trying to create a loop in python to loop through 2 data frames df1 and df2. However, I don't seem to be able to achieve this. Below is the code I am using:
import pandas as pd
import numpy as np
...
0
votes
1
answer
81
views
For loop in Pandas allows applying some changes to the df whereas discarding others
When having multiple df's to which similar changes need to be made I usually tend to use a for loop as a quick solution to avoid repetitive work.
I understand that the df change happening in the loop ...
1
vote
1
answer
38
views
Optimize Persistence Analysis with Rolling Windows in Pandas, Handling Overlaps Between Months
I’m relatively new to Python and coding in general. I’m working on a project to perform persistence analysis in a large dataset and am trying to avoid using for loops for efficiency. I’d appreciate ...
0
votes
2
answers
43
views
Pandas get first negative number from the bottom
I have following df. In which I want to see the first negative number after the last outcome number. & in the "first negative from last " col "this should occur or rather anything ...
1
vote
1
answer
49
views
Pandas get summation only on required cell of a columns
I have following table with "Rank" & "rice" columns as dataframe in pandas.
I want to have a sum in outcome col on the first positive rice col number. Also ignore the sum if ...
0
votes
1
answer
68
views
Counter that starts over for a specific variable
I'm writing a script to identify clusters of data in one dimension (depth) defined by a user specified gap in depth for multiple oil wells. The script looks at the difference in depth (d_dep) and then ...
0
votes
4
answers
172
views
Iteration over rows and apply function based on condition
I am learning iteration and apply function in pandas. I have an example below. for every 4 rows apply a function (1st row + 0 , 2nd row + 0, 3rd row = 0, 4th row = 0) and so on. Any link resources to ...
2
votes
2
answers
197
views
Iterating over each dataframe in a list of dataframes and changing name of first column
I'm trying to iterate through a list of datraframes and do two things, replace blanks with "_" (which I've done) and add a suffix to the first column of each dataframe. I know I can access ...
0
votes
2
answers
49
views
Iterate merge/VLOOKUP over multiple dataframes
I have multiple dataframes that I want to apply the same merge to.
data_1 = [[1, "Sarah"], [2, "Kevin"], [3, "Mark"]]
data_2 = [[1, "Bart"], [5, "Nina"...
1
vote
1
answer
63
views
Iterating over columns in multiple dataframes and conditionally performing an operation
I have three time series dataframes
df_list=[px, SC, SMA]
Each dataframe has identical columns and identical dates. I also have a list of securities (condensed for the purpose of the example):
...
0
votes
1
answer
66
views
Referencing prior rows and multiple columns in a calculation
I have a dataframe that looks like the below. You can see that, to start, the SMA column is a duplicate of the Index Value column intentionally. I'm trying to adjust the SMA column so that it will be ...
-1
votes
1
answer
51
views
Loop a number in the name of the DF and filtering
I want to create a loop from 1 to 8 to replace the #7 in each DF name and filtering of this code. How can I do this?
So far, my code is as follows:
df_sample_7 = df[df["quality"]==7]
...