How to make Python calendar show 3 letters instead of 2? - python-3.x

I have this code
import calendar
print(calendar.month(2020, 5))
print()
and it shows
May 2020
Mo Tu We Th Fr Sa Su
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
What i want to know is how i can manage it to show Mon Tue Wen Thu Fri Sat Sun instead of 2 letters
Well i solved it by adding w=3 to code so now it looks like this
import calendar
print(calendar.month(2020, 5, w=3))
print()
and the result is
May 2020
Mon Tue Wed Thu Fri Sat Sun
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Related

How to Display 3 month(i.e., January,Febuary,March) calendar of year 2020

I have recently started learning Linux(Ubuntu) Commands, I'm confused how to display 3 month calendar.
I have tried cal -y 2019 -A3 command but this command is Displaying first three months of 2020 after the calendar of 2019.
unix#unix:~$ cal -y 2019 -A3
2019
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 1 2
6 7 8 9 10 11 12 3 4 5 6 7 8 9 3 4 5 6 7 8 9
13 14 15 16 17 18 19 10 11 12 13 14 15 16 10 11 12 13 14 15 16
20 21 22 23 24 25 26 17 18 19 20 21 22 23 17 18 19 20 21 22 23
27 28 29 30 31 24 25 26 27 28 24 25 26 27 28 29 30
31
April May June
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 4 1
7 8 9 10 11 12 13 5 6 7 8 9 10 11 2 3 4 5 6 7 8
14 15 16 17 18 19 20 12 13 14 15 16 17 18 9 10 11 12 13 14 15
21 22 23 24 25 26 27 19 20 21 22 23 24 25 16 17 18 19 20 21 22
28 29 30 26 27 28 29 30 31 23 24 25 26 27 28 29
30
July August September
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 6 1 2 3 1 2 3 4 5 6 7
7 8 9 10 11 12 13 4 5 6 7 8 9 10 8 9 10 11 12 13 14
14 15 16 17 18 19 20 11 12 13 14 15 16 17 15 16 17 18 19 20 21
21 22 23 24 25 26 27 18 19 20 21 22 23 24 22 23 24 25 26 27 28
28 29 30 31 25 26 27 28 29 30 31 29 30
October November December
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 5 1 2 1 2 3 4 5 6 7
6 7 8 9 10 11 12 3 4 5 6 7 8 9 8 9 10 11 12 13 14
13 14 15 16 17 18 19 10 11 12 13 14 15 16 15 16 17 18 19 20 21
20 21 22 23 24 25 26 17 18 19 20 21 22 23 22 23 24 25 26 27 28
27 28 29 30 31 24 25 26 27 28 29 30 29 30 31
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
And I want the Output like this:
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
The cal utility options are significantly different between Debian/Ubuntu and RHEL/Fedora.
On Debian/Ubuntu:
$ cal jan 2020 -A2
2020
January February March
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
On RHEL/Fedora:
$ cal -n 3 jan 2000
January 2020 February 2020 March 2020
Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa
1 2 3 4 1 1 2 3 4 5 6 7
5 6 7 8 9 10 11 2 3 4 5 6 7 8 8 9 10 11 12 13 14
12 13 14 15 16 17 18 9 10 11 12 13 14 15 15 16 17 18 19 20 21
19 20 21 22 23 24 25 16 17 18 19 20 21 22 22 23 24 25 26 27 28
26 27 28 29 30 31 23 24 25 26 27 28 29 29 30 31
$

A for loop creates more integers than expect in bash

I have two dirs base and to_move. There are 10 files in base, which are named
0 1 2 3 4 5 6 7 8 9, and 3 files, 0 1 2, in to_move. What I want is to move the 3 files in to_move to base, with their names changed to 10 11 12.
Inside the dir to_move, I run the command
tmp=$(ls);for item in ${tmp[#]};do dst=$((item+10));echo $dst $item;done
what I got is
10 0
11 1
12 2
11 1
20 10
21 11
22 12
23 13
24 14
25 15
26 16
27 17
28 18
29 19
12 2
30 20
31 21
32 22
33 23
34 24
35 25
36 26
37 27
38 28
13 3
14 4
15 5
16 6
17 7
18 8
19 9
This makes no sense to me, it seems $(($item+10)) has some weird effects on $item.
Why this happens? And how can I modify the command to get this output?
10 0
11 1
12 2

How to return a matrix to a vector

Is there any way to return a matrix to a vector? I don't know the number of elements in the matrix, so let's say,matrix has n elements.
Below, it is an example of how I want to transform the table.
Any help, guidance, suggesting, recommendation will be very appreciated.
raw data.csv:
,January,February,March,April,May,June,July,August,September,October,November,December
2019,1,2,3,4,5,6,7,8,9,10,11,12
2018,13,14,15,16,17,18,19,20,21,22,23,24
2017,25,26,27,28,29,30,31,32,33,34,35,36
the link for csv files
raw=pd.read_csv('raw data.csv')
raw.head()
Unnamed: 0 January February March April May June July August September October November December
0 2019 1 2 3 4 5 6 7 8 9 10 11 12
1 2018 13 14 15 16 17 18 19 20 21 22 23 24
2 2017 25 26 27 28 29 30 31 32 33 34 35 36
final=pd.read_csv('Final.csv')
final.head(20)
Year&Month Value
0 2019 January 1
1 2019 February 2
2 2019 March 3
3 2019 April 4
4 2019 May 5
5 2019 June 6
6 2019 July 7
7 2019 August 8
8 2019 September 9
9 2019 October 10
10 2019 November 11
11 2019 December 12
12 2018 January 13
13 2018 February 14
14 2018 March 15
15 2018 April 16
16 2018 May 17
17 2018 June 18
18 2018 July 19
19 2018 August 20```
You can use pandas stack
df = pd.read_csv(r'raw data.csv')
df.set_index(df.columns[0]).stack().reset_index()
Out:
Unnamed: 0 level_1 0
0 2019 January 1
1 2019 February 2
2 2019 March 3
3 2019 April 4
4 2019 May 5
5 2019 June 6
6 2019 July 7
7 2019 August 8
8 2019 September 9
9 2019 October 10
10 2019 November 11
11 2019 December 12
12 2018 January 13
13 2018 February 14

Defining the range of a regression in which the X and Y will change

I need to create a simple regression with the Data Analysis Toolpack. The thing is, the range for Y and X input is always different. To illustrate what I'm trying to say, here's an example of the table I need to work on:
A B C D E F G H I J K L
1 Y T T1 T2 T3 T4 T5 T6 T7 T8 T9 T10
2 19 1
3 13 2 19
4 14 3 13 19
5 16 4 14 13 19
6 17 5 16 14 13 19
7 16 6 17 16 14 13 19
8 20 7 16 17 16 14 13 19
9 10 8 20 16 17 16 14 13 19
10 20 9 10 20 16 17 16 14 13 19
11 11 10 20 10 20 16 17 16 14 13 19
12 11 11 11 20 10 20 16 17 16 14 13 19
13 14 12 11 11 20 10 20 16 17 16 14 13
14 15 13 14 11 11 20 10 20 16 17 16 14
15 17 14 15 14 11 11 20 10 20 16 17 16
16 10 15 17 15 14 11 11 20 10 20 16 17
17 4 16 10 17 15 14 11 11 20 10 20 16
18 15 17 4 10 17 15 14 11 11 20 10 20
19 6 18 15 4 10 17 15 14 11 11 20 10
20 10 19 6 15 4 10 17 15 14 11 11 20
21 16 20 10 6 15 4 10 17 15 14 11 11
22 16 10 6 15 4 10 17 15 14 11
23 16 10 6 15 4 10 17 15 14
24 16 10 6 15 4 10 17 15
25 16 10 6 15 4 10 17
26 16 10 6 15 4 10
27 16 10 6 15 4
28 16 10 6 15
29 16 10 6
30 16 10
31 16
In this example, The Y input would be range A12:A21, that's because the first entry in the last column of the table (the "19" in cell L12) is in row 12 AND The last entry in the first column of the table (the "16" in cell A21) is in row 21; furthermore, The X input would be region B12:L21 for the same reasons.
After doing the first regression, I need to delete two columns out of the table and afterwards do ANOTHER regression. So if, for example I need to delete Columns J and L, the table would look like this:
A B C D E F G H I J
1 Y T T1 T2 T3 T4 T5 T6 T7 T9
2 19 1
3 13 2 19
4 14 3 13 19
5 16 4 14 13 19
6 17 5 16 14 13 19
7 16 6 17 16 14 13 19
8 20 7 16 17 16 14 13 19
9 10 8 20 16 17 16 14 13 19
10 20 9 10 20 16 17 16 14 13
11 11 10 20 10 20 16 17 16 14 19
12 11 11 11 20 10 20 16 17 16 13
13 14 12 11 11 20 10 20 16 17 14
14 15 13 14 11 11 20 10 20 16 16
15 17 14 15 14 11 11 20 10 20 17
16 10 15 17 15 14 11 11 20 10 16
17 4 16 10 17 15 14 11 11 20 20
18 15 17 4 10 17 15 14 11 11 10
19 6 18 15 4 10 17 15 14 11 20
20 10 19 6 15 4 10 17 15 14 11
21 16 20 10 6 15 4 10 17 15 11
22 16 10 6 15 4 10 17 14
23 16 10 6 15 4 10 15
24 16 10 6 15 4 17
25 16 10 6 15 10
26 16 10 6 4
27 16 10 15
28 16 6
29 10
30 16
And now the regression would be with inputs Y (A11:A21) because the first entry in the last column of the table ("19" in cell J11) is in row 11 AND The last entry in the first column of the table ("16" in cell A21) is in row 21. Likewise the X input would be (B11:J21) for the same reasons.
I have tried in a hundred different ways, but no luck. This is the closest I've been to creating what I need, but I'm still lost since it won't execute the regression:
Sub Prueba1()
Range("A1").Select
Selection.End(xlToRight).Select
Selection.End(xlDown).Select
Selection.End(xlToLeft).Select
Application.Run "ATPVBAEN.XLAM!Regress", Range(Selection, Selection.End(xlDown)).Select, _
Range(Selection.Offset(, 1), Selection.End(xlToRight)).Select, False, False, , Range("S1") _
, False, False, False, False, , False
End Sub
This User Defined Function (aka UDF) will return the range into your Application.Run "ATPVBAEN.XLAM!Regress" as a parameter.
Function regress_range()
Dim strAddr As String, c As Long
With Worksheets("Sheet4") '<~~set this worksheet name!
With .Cells(1, 1).CurrentRegion
Set regress_range = .Range(.Cells(.Cells(1, .Columns.Count).End(xlDown).Row, 1), _
.Cells(Application.Match(1E+99, .Columns(1)), .Columns.Count))
End With
End With
End Function
You need to make sure that it is properly referencing the correct worksheet in the third line.
This would become part of the run command like,
Application.Run "ATPVBAEN.XLAM!Regress", regress_range(), False, False, , Range("S1") _
, False, False, False, False, , False
I'm still concerned how Range("S1") may change (i.e. shift right) if columns are deleted from the regression range. Additionally, it has no explicitly referenced parent worksheet.
Output starting at your original data block:
$A$12:$L$21
$A$11:$J$21

Calculate Sum of Several Rows and Create Bar Graph Excel

I have a large set of values:
ID HOURS
29 9
29 9
29 8
29 9
29 10
29 9
29 9
29 7
29 9
29 9
29 8
29 10
29 8
29 9
29 9
29 8
29 9
29 10
29 9
29 9
29 8
29 6
29 9
29 9
29 6
29 9
29 8
29 9
29 9
29 8
29 9
29 9
29 8
29 9
29 9
29 9
29 8
29 10
29 9
29 7
29 10
29 8.5
29 8.5
29 7.5
29 7
29 6
29 9
29 8.5
29 10
29 9
29 8.5
29 9
29 9
29 8
29 8.5
29 8
29 9
29 8.5
29 8.5
29 10
29 8
29 7.5
29 7.5
29 7.5
29 9
29 7.5
29 9
29 10
29 10
29 8.5
29 7.5
29 8
29 8.5
29 9.5
29 7
29 9.5
29 9
29 8.5
29 8.5
29 7.5
29 8
29 8
29 8.5
29 9
29 8.5
29 9
29 9
29 8.5
29 9
29 10
29 9
29 8.5
29 9
29 7
29 9
28 7
28 8
28 9
28 8
28 7
28 9
28 9
28 9
28 8
28 9
28 9
28 8
28 9
28 9
... all the way to ID 1
There is a random number of hours for every ID, and I have to create a bar graph that sums up the values of each ID and displays them in a bar graph. I am very new to excel, how do I do this?
Say your id's are in column A, cells A1:A500, and your hours are in B1:B500.
Type out numbers 1-29 in a column, say in cells c1:c29. In cell D1, you can type =sumif($A$1:$A$500,C1, $B$1:$B$500).
Basically this sums the values in column B, if the values in column A equal C1. Now you can drag the formula down for all 29 values. From there, just graph.
You can also do this using a PivotChart.
Highlight the range of your data and choose Insert | PivotChart.
Choose a location for the chart.
Drag the ID field into the Axis Fields box and the Hours field into the ∑ values box.
You should get something like this.

Resources