Print Specific Rows and Columns in Pandas - python-2.7

I am having trouble printing certain values within my CSV.
I have a file that has 9 columns
Record_id Month Day Year Location_id Animal_id Sex Length Weight
and over 1000 rows.
I want to print Month , Day , and Year columns when the year is equivalent to 2002.
Because I have a lot of data I decided to only work with the first 5 rows where year is equal to 2002.
This is my code:
data.df.iloc[0:5, 1:4]
With this I can print the first 5 rows and the 3 columns I desire. However I can't figure out how to filter the year to be 2002

you can start by getting all the rows where year equal to 2002
with
filtered_data = df[df["Year"]==2002]
then you can apply your code to get only the first five rows and the three selected columns with
filtered_data.iloc[0:5, 1:4]

Related

Power BI substruct from salary for each person and month

My Table
Hi ,
I have this table in power bi . Each person has lines for each month passes . 5 months equals to 5 appearances in the list. for each line and the number of days ( between START AND END column) i want to substract from the MONEY column the MONEY PER MONTH COLUMN and keep the differnce .After this differnce to be substracted again with the column MONEY PER MONTH from this row until i have 0 . The only catch is that i want if the difference( happens a lot of times at month 5 out of 5 ) if the MONEY PER MONTH column is less than 20 , i want it to be 20 and the before result 240. After the last month when a new name record comes the money again to be 1040
BASICALLY I WANT TO FORM THE RED LINED COLUMN IN IMAGE BELOW COLUMN THAT I WANT TO ADD

Apply vlookup in previous month data on some columns

in 1 sheet i have data month wise with 5 columns.
I need to find vlookup for few columns in current month with previous month and look their value...in the same sheet

Power Bi DAX: Divide Value and set it for each week

I have a target value of 20 for January but it is 20 for the month, i need to show this over each week. I have to divide the target by 4 if there are 4 weeks in a month and by 5 if there are 5 weeks in a month. It is as simple as that, i am using a line and clustered column chart to display my data, i need the target spread out into each week of the month. I also need another field to do this but im sure i can replicate your formula and make it applicable.
I have added a WeeksinMonth column that counts how many weeks are in a particular month e.g January has 5 weeks and February has 4 weeks. I need an IF statement that will divide the target and value by how many weeks in a month. e.g if month has 5 weeks then divide target and value by 5, if month has 4 weeks divide target and value by 4.
I have a calendar table with week values which i can used to put the divided target into and also the desired output i made in excel (See attached).
How will i go about this?
Desired Output
Calendar Table
enter code hereYou can create an extra column in your calendar table:
WeekMax =
var stOfMonth = Weeks[Start of Week].[Month]
var stOfYear = Weeks[Start of Week].[year]
return CALCULATE(max(Weeks[Weekinmonth]);FILTER(Weeks;Weeks[Start of Week].[Month] = stOfMonth && Weeks[Start of Week].[Year] = stOfYear))
Make sure you have a relation in your model between calendar and target date. Now you can use this number for that week/date to divide by.
You can now add an extra column in your target table:
WeeklyTarget = Targets[Target]/Related(Calendar[WeekMax])

In sas application Set date parameter and put it in the contacted column to retrieve data in a certain period

The date in the table is not one set,
Days in the days column and months in the month column and years in the year column
I have concatenated the columns and then put these concatenation in where clause and put the parameter I have made but I got no result
I assume you are querying a date dimension table, and you want to extract the record that matches a certain date.
Solution:
I created a dates table to match with,
data dates;
input key day month year ;
datalines;
1 19 2 2018
2 20 2 2018
3 21 2 2018
4 22 2 2018
;;;
run;
Output:
In the where clause I parse the date '20feb2018'd using day, month & year functions: in SAS you have to quote the dates in [''d]
proc sql;
select * from dates
/*if you want to match todays' date: replace '20feb2018'd with today()*/
where day('20feb2018'd)=day and month('20feb2018'd)=month and year('20feb2018'd)=year;
quit;
Output:
if you compare date from day month and year, then use mdy function in where clause as shown below. it is not totally clear what you are looking for.
proc sql;
select * from dates
where mdy(month,day, year) between '19feb2018'd and '21feb2018'd ;

Calculate previous year based on this year condition

Let's say i have a table called Orders with number of units sold by resellers in Country by date
Country ResellerID Date Units
3 1 May-17 7
3 1 May-16 4
3 2 May-16 3
2 3 May-16 5
2 3 May-17 8
I have to compare total units sold in specific month basing on a slicer selection to the last year total units in the corresponding month. This is relatively easy and I do this using the formula below
UnitsLastYear = CALCULATE(SUM(Orders[Units]),SAMEPERIODLASTYEAR(Orders[Date]))
So for May-17 chosen on the slicer I have:
This year = 15
Last Year = 12
However there is another condition for calculating last year's value and this is that I should only take Resellers that sold anything in current year's selected month so in this example ResellerID = 2 should be excluded from last year calculation and Last Year should have value of 9
Does anyone can help how to transform this calculation so that it would rflect this condition?
Try modifying it to the following:
= CALCULATE(SUM(Orders[Units]),
SAMEPERIODLASTYEAR(Orders[Date]),
Orders[ResellerID] IN VALUES(Orders[ResellerID]))
This will only sum the [ResellerID] values that appear in the current filter context. Since there are no ResellerID = 2 in May-17, those are excluded from the previous year calculation.