How to count the elements in a "cell" with pandas [closed] - python-3.x

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I am trying to create a new colunm in a df that returns number of elements of a column row by row.
I tried this
df['Elements'] = len(df['Goals']) sadly all I get is column full of the same number, I understand what is returning are not the elements that the columns 'Goals' has in every row but all the elements included in the column 'Goals' in total. I do not know how to get the len() of the list included in the row.
Could someone help me, I would really appreciate it

I think you're looking for str.len():
https://pandas.pydata.org/pandas-docs/stable/user_guide/text.html
df['Elements'] = df['Goals'].str.len()

You can do it with pandas.Dataframe.apply:
df['Elements'] = df['Goals'].apply(len)

Related

How do I select and return all rows in excel with the same value is a particular column [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 days ago.
Improve this question
I want to return all rows in a particular dataset, with the value in a particular column. Without writing multiple vlookup statements and manually filtering the data. Can I do this using VBA, where it selects the data and creates new excel workbooks with this data?
I tried indexing, but it doesn't quite do what I want

Return list of all values that match criteria to one or more cells [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last month.
Improve this question
i to pick all zip codes(A:A) by city(C) and county (D)
I need to look like
is that posible? i need to remove all duplicates and get all zip codes for every county
You'd want TEXTJOIN() and FILTER(), where the 2nd parameter of FILTER() holds a boolean structure:
=TEXTJOIN(" ",FILTER(A$2:A$30,(C$2:C$30=B2)*(D$2:D$30=C2)))

I want To Convert Object To Integer or Float i'm trying since one day but i'm unable to find a solution please let me know the answer [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
enter image description here
enter image description here
Please go through the images.... sir
i have 4 columns which have object values like 1,254 , 1,256, 1,489.... like this.... and these are in the Object Format and i want to convert these values into Int but i'm getting an error like
ValueError: could not convert string to float: '1,259.11'
please help me i'm trying since 1 day but i'm unable to get it please help me out
It may be because you've got commas in the data, so pandas thinks it's a string. Try removing the commas then converting the column to a float:
temp["Close Price"] = temp["Close Price"].str.replace(",","")
Use replace first to remove comma from string and then convert it to float.
Ex.:
df.apply(lambda x: x.str.replace(',','').astype('float'))
a b
0 1259.11 1259.11
1 1257.63 1257.63
To apply on specific columns select columns using iloc or loc so For you it would be
temp.iloc[:,1:5] = temp.iloc[:,1:5].apply(lambda x: x.str.replace(',','').astype('float'))

Excel formula to extract string from text [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I'm using the following formula to extract a string from text in a cell by getting rid of -DCS.
The text contained in the cell: Q074-SARE_MANSONG-DCS
Formula:IF(ISNUMBER(SEARCH("DCS",H22)),LEFT(H22,FIND("#",SUBSTITUTE(H22,"-DCS","#",LEN(H22)-LEN(SUBSTITUTE(H22,"-",""))))-1),([#[<HELPER><SITE>]]))
Desired reslut: Q074-SARE_MANSONG
The problem is that it is not working for all cells. Can someone please tell me what it is that I'm doing wrong. Thanks.
If "-DCS" is always at the end of the string:
=SUBSTITUTE(A1,"-DCS","")
Use one of these formulas instead (assuming your data is in A1)
=left(A1,len(A1)-4) or =SUBSTITUTE(A1,"-DCS","")

Using Excel to verify entries [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 looking for a way to automate checking a demographic sheet filled in by a trainee against an answer key.
Our sheet currently has data validation built in to return TRUE or FALSE on whether the answer matches the answer key, but I'm looking for a way to then display the exact text string, so as to provide feedback on the exact error.
For example the way it currently functions is:
Sheet1!A1=Cat
Sheet2!A1=Dog
Sheet3!A1=FALSE
What I'm looking for, is a to utilize VBA to generate a comment balloon on Sheet3!A1 and see the exact error for easier feedback.
I'm new to working with advanced functions in Excel, so if anyone has a pointer in the right direction, I would greatly appreciate it!!
I Suppose your want to check Sheet1 = Sheet2 in sheet3, and show the error if does not match.
To make it simple, just use formula in sheet 3,
=IF(Sheet1!A1=Sheet2!A1,"",Sheet1!A1 & "|" &Sheet2!A1)
if they match, nothing will be show, if they don't match, it will show Sheet1figure|Sheet2figure
this is easier than showing True/False

Resources