Pandas: Multiply a column based on a different columns condition [closed] - python

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am using Python with Pandas. How can I multiply a column by 1000 given another column has a certain string?

This should do it.
df['columnname'] = np.where(df['othercolumn'] == 'CertainString',
df['columnname'] * 1000,
df['columnname'])

Related

Calculate the 3 sigma value using python [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have one data frame in python. How can I calculate the 3sigma value for each column of my data frame using python? please help me with this.
The command you're looking for is df.std() * 3

Average counts in a column with condition of another column in Pandas [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have dataframe like this
enter image description here
I need to find out the average close days of request Recycling
Please help me.
You can group by request and get the average.This will give average for each group
df.groupby("request")["Days to Close"].mean()

Write a python code to merge two list with the following condition [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
If two list is having same number, then the final list should not have the number
If your lists contains unique elements, consider using sets instead.
https://docs.python.org/2/library/sets.html
Check this code:
ls=[1,2,3,4,5,5]
ls1=[1,2,3,4,5,7,8,9]
common_elements=set(ls).intersection(set(ls1))
for i in common_elements:
if ls.__contains__(i):
ls.remove(i)
if ls1.__contains__(i):
ls1.remove(i)
final_ls=ls+ls1
print(final_ls)

How to view dataframe columns based on a condition? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
For the above example,
I want to have a look at the value of outlet_size when Outlet_identifier = OUT049 or any value for that instance.
I don't want to produce a new dataframe object and then print it, instead I want to know if there is any function or way to directly view it.
For both columns
df.loc[df['Outlet_identifier'].eq('OUT049'), ['Outlet_identifier', 'outlet_size']]
you can do that with pandas like this :
df = pd.DataFrame({'Outlet_identifier': ['OUT049','OUT018','OUT049'], 'outlet_size':
[2.0, 2.0, 2.0]})
df[df["Outlet_identifier"]=="OUT049"]["outlet_size"]

add index of values in between elements in a string [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
For example:
input: "Orange"
output: "O0r1a2n3g4e5"
I know I will have to convert the string to a list so I can iterate and append the index numbers, but I don't know how to do that in code.
''.join([f'{letter}{index}' for index, letter in enumerate(input)])

Categories

Resources