All Questions
2,447 questions
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
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 ...
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]
...
0
votes
0
answers
66
views
How to get every combination possible in a for aggregatation
I'm trying to get every combination possible using a list of columns so that I can perform an aggregate function based on column i which is not in the columns list.
I was able to use the code below to ...
1
vote
1
answer
57
views
What tool should I use to create new column in dataframe based on multiple condition
I have column (Column1) in dataframe that contain information about work centers and values that I need to assign names of these work centers in empty column (Column2), example:
Input:
Column1:
...
0
votes
1
answer
42
views
Create a new column based on other columns for time series data in pandas
I have the following pandas dataframe with columns May, June, and July.
Month
June
July
Aug
June
a
d
g
July
b
e
h
Aug
c
f
i
I want to create a several new columns with a 1 month forecast, 2 month ...
1
vote
2
answers
369
views
How to calculate the Relative Strength Index (RSI) through record iterations in pandas dataframe
I have created a pandas dataframe as follows:
import pandas as pd
import numpy as np
ds = { 'trend' : [1,1,1,1,2,2,3,3,3,3,3,3,4,4,4,4,4], 'price' : [23,43,56,21,43,55,54,32,9,12,11,12,23,3,2,1,1]...