How to get the cumulative count based on other column in googlesheets? - google-sheets

I was trying to create a column with cumulative count per day from a column in google sheet but I was unable to do so.
How to get the cumulative counts?
Public spreadsheet: https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=1126759670
Question
Find cumulative number per day. Eg for May 7 start from 1,2,3 and for May 8 again start from 1,2,3 and so on.
Required
I need the cumulative count for each day as shown in the figure.

In J2 I entered
=Arrayformula(IF(LEN(A2:A), ROW(C2:C)-MATCH(C2:C, C2:C,0),))
See if that works for you?

Also
=ArrayFormula(if(C2:C<>"",countifs(C2:C,C2:C,row(C2:C),"<="&row(C2:C)),))

If you are interested using gspread module, you can get the new column as follows:
import os
import glob
import numpy as np
import pandas as pd
import gspread
path_creds = os.path.expanduser('~/.config/gspread/credentials.json')
gc = gspread.service_account(filename=path_creds) # google service
url = "https://docs.google.com/spreadsheets/d/10NzbtJhQj4hQBnZXcmwise3bLBIAWrE0qwSus_bz7a0/edit#gid=1126759670"
parts = url.split('/edit')
url = parts[0]
sh = gc.open_by_url(url)
ws = sh.sheet1
res = ws.get_all_records()
df = pd.DataFrame(res)
df['answer'] = df.groupby('Date')['Company'].transform('cumcount')+1
df
output

Related

Google Sheets Divide Results of the Import Range

I have this GoogleSheets,
With a import range query : =IMPORTRANGE("1Z76YA8","'Sales'!1:1")
Is it possible to divide the results of my import range with "row 1 (currency euro) "?
=ARRAYFORMULA(IMPORTRANGE("1Z76YA8","'Sales'!1:1")/B1:1)
If you do not want to output when row 1 is blank:
=ARRAYFORMULA(IF(B1:B="",,IMPORTRANGE("1Z76YA8","'Sales'!1:1")/B1:1))

Google Sheets QUERY of discontinuous columns in order to import desired range

I have two google sheets in the same workbook and I am trying to import certain columns from one into the other sheet based on what hour of class was chosen. For example, I have the Date in column A, Name in B, Email in C, and Number in D and other stuff, then the Class in I.
Column A - Date
Column B - Name
Column C - Email
Column D - Number
...
Column I - Class
My goal is to import column B through D if column I has a certain class. I tried a using this if statemnt: =if('Confirmação'!I2 = A1,(=importrange("sheet_url","Confirmação!B2:D2")), "NOPE")
where A1 has the name of the class to look for, but it resulted in a #Error.
Then I tried a variety of query such as the following:
=QUERY({'Confirmação'!B2:D2,'Confirmação'!I2},"Where I = 'Terça 19h English 1'")
=QUERY({'Confirmação'!B2:D2, 'Confirmação'!I2},"Where 'Confirmação'!I = 'Terça 19h English 1'")
and also added the IfError: =iferror(QUERY('Confirmação'!B4:I4,"Where I = 'Terça 19h English 1'"),"Vaga")
Could someone correct my functions or help with a google script? Thank you! Very much appreciated! (Sorry about the Portugues-it's a project I am working on in Brazil)
In case you still want to do it using QUERY:
Using your formula with slight modification:
=QUERY({'Confirmação'!B2:D2,'Confirmação'!I2},"select * where Col3 = 'Terça 19h English 1'").
In case you want the formula to take the class name dynamically, then you can modify the formula to =QUERY({'Confirmação'!B2:D2,'Confirmação'!I2},"select * where Col3 = '"&A1&"'") where A1 is the cell with the class name.
Instead of using a QUERY, you can use the =FILTER() function to solve your problem. Doing the following:
=FILTER('OriginSheet'!B:D;'OriginSheet'!I:I = 'Certain Class')
Then you can still add more conditions:
=FILTER('OriginSheet'!B:D;'OriginSheet'!I:I = 'Class 1';'OriginSheet'!I:I = 'Class 2';'OriginSheet'!I:I = 'Class 3')
Try that and let me know if it worked.

Import a Coingecko table to Google Spread Sheets

I want to import the TOP LOOSERS table from this page to a Google Spreadsheet but I have no idea whatsoever how to do it.
You can import data by this way, i.e in D2
=IMPORTHTML("https://www.coingecko.com/fr","table",1)
but it is difficult to order the result since values are in string format including %. You can then compute in A3, with % format in column B
=query(arrayformula({F3:F,1*(J3:J)}),"select * order by Col2 limit 10")
https://docs.google.com/spreadsheets/d/1ZSonplM0DqXBaggACVo906AYz1ys9k_xrDzogb-k0sQ/copy

How to filter Excel column?

I am looking for a solution in python for my data which is in an excel file that contains different statements and numbers. I want to filter out the rows on the base of column values.
import pandas as pd
df=pd.read.excel("Data.xlsx")
df[df.Numbers.apply(lambda x: str(x).isdigit())]
df.to_excel("Data1.xlsx")
Any suggestions please?
Here is one way to perform the filtering, using pandas' string tools and boolean masks. I did each step separately (easier to test, and easier to understand in the future).
# remove CAS and Cascade
mask = (df['Evaluations'].str.startswith('CAS') |
df['Evaluations'].str.contains('CASCADE'))
df = df[~mask]
# remove Numbers starting with 21 or 99
mask = (df['Numbers'].astype(str).str.startswith('21') |
df['Numbers'].astype(str).str.startswith('99'))
df = df[~mask]
# remove letter as 2th character (1 => zero-based indexing)
mask = df['Numbers'].astype(str).apply(lambda x: x[1].isalpha())
df = df[~mask]
# write to file
with open('Data1.xlsx', 'wb') as handle:
df.to_excel(handle)
print(df)
Evaluations Numbers
2 Nastolgic behaviours of people 75903324
3 google drive 76308764
6 Tesla's new inventions 83492836
7 Electric cars 78363522
1- If in the column named Evaluations, its content starts with "OBS" or has the word "Obsolete" in it then remove these rows
(^OBS|Obsolete)
2- If the column value in the Numbers column start with digits "99" or "51" then remove these rows
^(99|51)
3- If the 5th digit in the Numbers column is an alphabetic character then also remove these rows
^\d{4}\w
These are the Regexes that will help match these conditions.

How to copy hyperlinks using xlrd, xlwt and xlutils?

Problem:
I am trying a simple code for writting excel sheet. The program checks if the Excel sheet already exists, If the file exists, then it append it with the new data. The problem is I am unable to copy hyperlinks as xlrd fail to read hyperlinks. I would be very thankful if anyone can suggest me some way.
I am using xlrd (0.9.2), xlwt(0.7.5) and xlutil1.6.0)
Note: I had used here some default example for hyperlinks. I will be using this information for my other program where I am suppose to edit excel workbook with many sheets and every sheet containing hyperlinks at multiple places.
Code:
from xlwt import *
import xlrd as xr
import os
from xlutils.copy import copy
name=r"hyperlinks.xls"
if os.path.exists(name)==True:
print "Excel sheet already exists!!!"
cwb=xr.open_workbook(name,formatting_info=True)
w=copy(cwb)
temp=cwb.sheet_by_index(0)
ws=w.get_sheet(0)
row=len(temp.col_values(0))
n = "HYPERLINK"
ws.write_merge(row+1, row+1,1, 10, Formula(n +'("C://abc.jpg";"pic")'))
w.save("hyperlinks.xls")
else:
w = Workbook()
ws = w.add_sheet('F')
n = "HYPERLINK"
ws.write_merge(row+1, row+1,1, 10, Formula(n +'("C://abc.jpg";"pic")'))
w.save("hyperlinks.xls")
Thanks for your help!!!

Resources