how to do conditional replacing using vim
Date : March 29 2020, 07:55 AM
To fix this issue I want to replace word with WORD, but only on the lines which start with -. Anybody knows how to do it? :%g/^-/s/word/WORD/g
|
Python Pandas replacing nan's in one column conditional on observations in another column
Date : March 29 2020, 07:55 AM
it fixes the issue This was a bit more annoying to code, basically we can apply a custom function that performs the lookup for you: In [106]:
# define our function
def func(x):
# test to see if the asterisk is present
if x.find('*') > 0:
# perform a lookup on a slice of the passed in string
return(current_data.loc[current_data.X==x[0:x.find('*')],'Y'].values.max())
# using loc assign to column 'Y' where it is null the returned calculation of the apply
current_data.loc[current_data.Y.isnull(),'Y'] = current_data[current_data.Y.isnull()]['X'].apply(func)
current_data
Out[106]:
X Y
0 3*NY 4
1 3 4
2 2 5
3 2*NY 5
4 1 8
5 7 NaN
|
python pandas replacing column values conditional on string patterns and using split()
Tag : regex , By : kuba53280
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further This is a response to your second question (you should stick to one question per post). df.loc[:, ['e0', 'e1']].apply(lambda x: x.str.strip())
|
Replacing conditional with something?
Tag : chash , By : bdurbin
Date : March 29 2020, 07:55 AM
I wish this help you The pattern I would use here is just encapsulation. The nesting here is hard to follow, and worsened by the equality comparisons. If possible, instead of exposing the raw field, try encapsulating the intent. e.g. Instead of if (data.ApplicationPurpose == ApplicationPurpose.Renewal) try extending ApplicationStatusData with a property like bool IsRenewalApplication
{
get
{
return this.ApplicationPurpose == ApplicationPurpose.Renewal;
}
}
|
Replacing DataFrame index values in python with conditional argument
Date : March 29 2020, 07:55 AM
like below fixes the issue In pandas for replace values in index or columns is used function rename: df = df.rename(d)
print (df)
Country
South Korea 12
United States 13
United Kingdom 14
Hong Kong 15
df = pd.concat([df] * 100000)
In [11]: %timeit df.rename(d)
10 loops, best of 3: 75.7 ms per loop
In [12]: %timeit pd.Series(df.index).replace(d)
10 loops, best of 3: 71.8 ms per loop
In [13]: %timeit pd.Series(df.index.values).replace(d)
10 loops, best of 3: 75.3 ms per loop
|