How to iterate through multiple start and end dates in a python dataframe - python-3.6

I have a dataframe with multiple start and end dates. I am planning to run a query for eaƧh of the rows and append the outcome.
Output I wish is , parse these dates into a query and calculate views in the daterange.
query: select count() as views from views where date between {start} and {end}
output with 3 columns start end views
start end. views

Related

Writing a SPARQL query that constructs new triples with result from COUNT in an aggregate

I'm working with the Snap SPARQL tool in Protege so to add data into the ontology I have to use CONSTRUCT because it doesn't support INSERT (the tool gives the option to assert the new triples constructed back into the ontology). I want to count values with a specific value and assert the count of those values back into the ontology. I created a little test ontology regarding students and grades to help me figure this out. I have the following query which works:
SELECT ?student (COUNT(?test) AS ?tcount)
WHERE {?student test:tookTest ?test.
?test test:hasGrade test:A.}
GROUP BY ?student
This gives me a table with each student in one column and their number of A grades in the next. What I want to do next is to use the ?tcount to assert the data back into the ontology. I've tried various things like replacing the SELECT with a CONSTRUCT or using an embedded query:
CONSTRUCT {?student test:hasACount ?tcount.}
WHERE {
SELECT ?student (COUNT(?test) AS ?tcount)
WHERE {?student test:tookTest ?test.
?test test:hasGrade test:A.}
GROUP BY ?student}
I think the problem with this is that ?tcount isn't in scope of the surrounding query. I've tried several different options like using BIND to BIND ?tcount or grouping by ?tcount rather than ?student but no luck.

Hive - Filter on Map data type column stuck

We have a table with one year of data in daily date partition. Each day has 100 billion rows. The table has a map data type column which holds a 100000+ key-value pair. All I need is min(date) based on the two map column filter. YARN is stuck with deciding a number of mapper for this query. I only see the below message when I invoke the query and it stuck for more than 30+ minutes. Then I killed the job. Is there a way to optimize and run the query?
Launching Job 1 out of 1
Number of reduce tasks determined at compile time: 1
In order to change the average load for a reducer (in bytes):
set hive.exec.reducers.bytes.per.reducer=
In order to limit the maximum number of reducers:
set hive.exec.reducers.max=
In order to set a constant number of reducers:
set mapreduce.job.reduces=
Query:
select min(data_dt) from my_db.logs
where txttype = 'abcd'
and mapfields['page_name'] in ('a','b','c','d','e','d')
-- Total 50 page names
and mapfields['usedIn'] like '%Group%'
and (ctry like 'aa%' or ctry like 'bb%' or ctry like 'cc%')
;

Generating dates from field on Sqlite with CTE

I need a duplicated on sqlite of the generate_series() function of PostgreSQL. I have a table where I need to calculate the future payments based in 2 fields:
Date Period
----------------
1-1-2000 60
1-2-2000 40
1-3-2000 50
So, from the first row, I need to build 60 dates starting at 1-1-2000.
I read
How to generate all dates between two dates
and discover that sqlite have CTE! But can't figure out how build the query. The samples I found have values hardcoded.
First, you should avoid provided date format. Use one of supported ones (check SQLite Date and Time Functions).
CREATE TABLE source_table (Date, Period);
INSERT INTO source_table VALUES("2000-01-01",60),("2000-02-01",40),("2000-03-01",50);
WITH dates AS (
SELECT * FROM source_table
UNION -- use UNION ALL if repeated dates are desired
SELECT DATE(JULIANDAY(Date)+1), Period-1 FROM dates WHERE Period>0
) SELECT Date FROM dates ORDER BY Date;

Can I bin data in SQLite?

I have a lot of rows with dates in some SQLite database. I'd like to get some aggregated statistics for weeks or some other periods.
Is it possible to bin data in SQLite (i.e. get some number which corresponds to the number of the period - e.g. week)?
To create a column of unique week identifiers use strftime('%Y%W', date_column). More info here.
For your purposes I believe a "SELECT ... GROUP BY strftime('%Y%W', date_column)" should work.

How to calculate number of days by two dates in SSRS formula field

I have an SSRS report and I have a table there, in which I have a column named as No. Of Days which are lying between two dates. I am getting those dates (datetime) through datasource but don't know how to calculate number of days between these two dates in a tablix cell formula.
The following will get the difference between two dates:
=DateDiff("d","01-Jun-2011","10-Jun-2011")
which results in 9.
In a table cell it will be something like:
=DateDiff("d",YourDataSet.Fields!FirstDate.Value, YourDataSet.Fields!SecondDate.Value)

Resources