How to view dataframe columns based on a 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 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"]

Related

Alternatives to Write isnull().sum()? [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 19 hours ago.
Improve this question
import pandas as pd
Data = pd.open_csv('file name')
Data = isnull().sum()
I know that here we are testing each cell if it were empty or not; then, return the summation of empty ones.
Is there any other ways to re-write the statement?
Can we store the True results in a data structure, add them using a loop, and return the result?

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)

What exactly does this code do to a dataframe? [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 3 years ago.
Improve this question
Hey guys I was wondering what exactly this code does, how does it iterate through the dataframe and what exactly does the lambda function do?
df.apply(lambda x: pd.Series(x.dropna().values))
The above block of code traverses the data frame column-wise and drops NA values. Lambda functions are the anonymous functions that are well explained in this text.

Pandas: Multiply a column based on a different columns 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 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'])

Categories

Resources