code-rag-bench/online-tutorials huggingface dataset:
PHP | mysqli_fetch_array() Function

23 Apr, 2020
The mysqli_fetch_array() function is used to fetch rows from the database and store them as an array. The array can be fetched as an associative array, as a numeric array or both.
Associative arrays are the arrays where the indexes are the names of the individual columns of the table. On the other hand, numeric arrays are arrays where indexes are numbers, with 0 representing the first column and n-1 representing the last column of an n-column table.
Syntax:
mysqli_fetch_array ("database_name", "mode")

Parameters: This function accepts two parameters as mentioned above and described below:
database_name: It is the database on which operations are being performed. It is a mandatory parameter.
mode: It can have three values – MYSQLI_ASSOC, MYSQLI_NUM, and MYSQLI_BOTH. MYSQLI_ASSOC makes the function behave like mysqli_fetch_assoc() function, fetching an associative array, MYSQLI_NUM makes the function behave like mysqli_fetch_row() function, fetching a numeric array while MYSQLI_BOTH stores the data fetched in an array that can be accessed using both column indexes as well as column names.
Program:
<?php  $conn = mysqli_connect(    "localhost", "root", "", "Persons");         // Check connection if (mysqli_connect_errno()) {     echo "Database connection failed."; }   $sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";$result -> $mysqli -> query($sql);  // Numeric array$row = mysqli_fetch_array($conn, MYSQLI_NUM);printf ("%s (%s)\n", $row[0], $row[1]);  printf("\n");  // Associative array$row = mysqli_fetch_array($conn, MYSQLI_ASSOC);printf ("%s (%s)\n", $row["Firstname"], $row["Lastname"]);  mysqli_close($conn);?>
For the above table, the output will be:Output:
A    B
C    D
E    F
G    H

A    B
C    D
E    F
G    H

PHP-function
PHP-MySQL
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to execute PHP code using command line ?
PHP in_array() Function
How to delete an array element based on key in PHP?
How to Insert Form Data into Database using PHP ?
How to convert array to string in PHP ?
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Scala Iterator map() method with example - GeeksforGeeks

13 Aug, 2019
The map() method belongs to the concrete value member of the class Abstract Iterator. It is utilized to build a new iterator by applying a function to each of the elements of the stated iterator.
Method Definition:
def map[B](f: (A) => B): Iterator[B]

where, B is the element type of the returned iterator and f is the function to be applied on each element of the iterator.Return Type:It returns a new iterator from the stated iterator after applying the function to each element of the given iterator.Example #1:
// Scala program of map()// method  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Creating an Iterator         val iter = Iterator(3, 6, 15, 19, 21)                  // Applying map method        val iter1 = iter.map(x=>{x*3})                  // Applying next method        val result = iter1.next()                  // Again applying next method        val result1 = iter1.next()                  // Displays output        println(result)        println(result1)              }}
9
18

Here, the function is applied to all the elements of the stated iterator and we can see here for the first two elements, where three is multiplied to each of them, similarly it is multiplied to all the elements of the stated iterator resulting into a new iterator.Example #2:
// Scala program of map()// method  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Creating an Iterator         val iter = Iterator(3, 6, 15, 19, 21)                  // Applying map method        val iter1 = iter.map(y=>{y/3})                  // Applying next method        val result= iter1.next()                  // Again applying next method        val result1= iter1.next()                  // Displays output        println(result)        println(result1)              }}
1
2

Here, first two elements will be divided by three and will get the result into a new iterator.
Scala
Scala-Method
Scala
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Inheritance in Scala
Hello World in Scala
Scala | Option
How to install Scala on Windows?
Scala | Case Class and Case Object
Scala Map get() method with example
Scala | Decision Making (if, if-else, Nested if-else, if-else if)
Scala List map() method with example
Scala List exists() method with example
How to create boxplot for a list object in base R?

A list object can contain multiple elements of data, also the size of the data may vary. If a list object has numerical vectors then the boxplot for each of the elements can be created simply by using boxplot function. For example, if we have a list object called LIST that contains five numerical vectors then the boxplot for each of the vectors can be created by using the command boxplot(LIST)
 Live Demo
List<-list(x1=rnorm(50),x2=rnorm(50,5,2.25),x3=rpois(20,5),x4=rexp(50,2.24))
List
$x1
[1]  0.47673123  -0.13988530 -0.03454116 -1.07172674 -0.07038959  0.84246745
[7] -0.24880770  -0.16358068  0.58943824 -0.02419312  1.23205397  0.41819088
[13] -0.18096917 -0.66329446  0.59654575 -0.38813742  0.11389223  0.34736194
[19] -1.02731203 -1.00254775 -0.12265414 -0.26374874  0.70882415  0.94992258
[25]  0.94381547 -0.96601086  0.64740016  1.11793512  1.17730331  1.71042415
[31] -0.41691694 -0.96920255  0.41512216  1.26071518 -0.14539137 -1.16879555
[37]  1.38377334  3.45037406  1.35805370  0.47444658 -0.49433200 -0.36656357
[43] -0.21815763 -0.74840666  0.26719190  1.20493116  1.60986589 -0.60518029
[49] -0.41968672 -0.32073967
$x2
[1]  5.8796314 5.7298751 5.3845408 3.1797638 4.7799172 6.9741100 7.9921069
[8]  9.5581477 2.2260415 1.0497262 4.2621598 3.3089075 4.8928650 7.3186556
[15] 4.9003319 5.3323320 6.5852322 2.6108129 5.5484016 3.1658888 5.5651849
[22] 3.9454364 1.2637536 3.1110510 0.5324844 5.9578925 8.1218069 2.9446954
[29] 8.5903533 5.5571433 0.5557869 5.0468930 3.9626768 3.4359655 2.1267040
[36] 5.3730887 3.4845970 6.1972562 2.9490418 4.0302330 7.4539694 6.6024379
[43] 6.4314803 3.6497954 3.3413132 6.1229056 3.5588145 6.1242543 3.5965840
[50] 8.6095519
$x3
[1] 2 0 8 5 2 3 6 4 5 11 6 6 7 3 6 3 4 12 6 5
$x4
[1]  0.585750982 0.370122795 1.987015464 0.024077675 0.032587786 0.997293306
[7]  0.130429262 0.422050875 0.348886654 0.106149101 1.439493919 0.105526681
[13] 0.609840540 0.196605252 0.671462334 0.196896603 0.265777491 0.987109188
[19] 0.177649340 0.310512653 0.169546605 0.356390141 1.055593510 0.401508889
[25] 0.785761516 0.430135796 0.274123388 0.823727150 0.613929177 0.264846348
[31] 0.904656444 0.089555490 0.110510149 0.461548606 0.017619161 1.007491679
[37] 0.329095102 0.338861211 0.004771366 0.861360820 0.059209099 1.097892124
[43] 0.071317813 0.372330993 0.168262454 0.562485840 0.465475293 0.287788140
[49] 1.282085210 1.655309706
boxplot(List)
time.Time.Second() Function in Golang with Examples - GeeksforGeeks

19 Apr, 2020
In Go language, time packages supplies functionality for determining as well as viewing time. The Time.Second() function in Go language is used to find the second offset within the minute as provided by “t” and the range is [0, 59]. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.
Syntax:
func (t Time) Second() int

Here, “t” is the stated time.
Return Value: It returns the second offset within the minute as provided by “t”.
Example 1:
// Golang program to illustrate the usage of// Time.Second() function  // Including main packagepackage main  // Importing fmt and timeimport "fmt"import "time"  // Calling mainfunc main() {      // Declaring t in UTC    t := time.Date(2017, 2, 3, 13,              12, 34, 50, time.UTC)      // Calling Second method    sec := t.Second()      // Prints second as specified    fmt.Printf("The stated second is: %v\n", sec)}
Output:
The stated second is: 34

Example 2:
// Golang program to illustrate the usage of// Time.Second() function  // Including main packagepackage main  // Importing fmt and timeimport "fmt"import "time"  // Calling mainfunc main() {      // Declaring t in UTC    t := time.Date(2017, 2, 3, 13,             12, 67, 50, time.UTC)      // Calling Second method    sec := t.Second()      // Prints second as specified    fmt.Printf("The stated second is: %v\n", sec)}
Output:
The stated second is: 7

Here, the seconds stated in the above code is out of usual range but it is normalized while conversion.
GoLang-time
Go Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Strings in Golang
Time Durations in Golang
How to Parse JSON in Golang?
6 Best Books to Learn Go Programming Language
Structures in Golang
Defer Keyword in Golang
How to iterate over an Array using for loop in Golang?
Rune in Golang
Class and Object in Golang
Loops in Go Language
Python – Obtain title, views and likes of YouTube video using BeautifulSoup

29 Dec, 2020
In this article, we will learn how can we obtain data (like title, views, likes, dislikes etc) from any YouTube video using a Python script. For this task, we are going to use very famous library for web scraping BeautifulSoup and Requests.
Modules required and Installation :
Requests :Requests allows you to send HTTP/1.1 requests extremely easily. There’s no need to manually add query strings to your URLs.
pip install requests
Beautiful Soup:Beautiful Soup is a library that makes it easy to scrape information from web pages. It sits atop an HTML or XML parser, providing Pythonic idioms for iterating, searching, and modifying the parse tree.
pip install beautifulsoup4
For a given URL of video, data scraping will be done. Then parsing of data (title, views, likes element) will be done using find() method of Beautiful Soup. It will find and store the values in the dictionary.
Code :
# importing the librariesfrom bs4 import BeautifulSoupimport requests  # creating functiondef scrape_info(url):          # getting the request from url    r = requests.get(url)          # converting the text    s = BeautifulSoup(r.text, "html.parser")          # finding meta info for title    title = s.find("span", class_="watch-title").text.replace("\n", "")          # finding meta info for views    views = s.find("div", class_="watch-view-count").text          # finding meta info for likes    likes = s.find("span", class_="like-button-renderer").span.button.text          # saving this data in dictionary    data = {'title':title, 'views':views, 'likes':likes}          # returning the dictionary    return data  # main functionif __name__ == "__main__":          # URL of the video    url ="https://www.youtube.com/watch?time_continue=17&v=2wEA8nuThj8"          # calling the function    data = scrape_info(url)          # printing the dictionary    print(data)
Output:
{‘title’: ‘ Placement100 | GeeksforGeeks ‘, ‘views’: ’18, 964 views’, ‘likes’: ’37’}
Python web-scraping-exercises
Python-BS3
Python-requests
Web-scraping
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Different ways to create Pandas Dataframe
Enumerate() in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Convert integer to string in Python
Python OOPs Concepts
Python | os.path.join() method
How to drop one or multiple columns in Pandas Dataframe
How to create a pop-up div on mouse over and stay when click using jQuery ?

21 May, 2021
In this article, we will learn how to create a pop-up div on mouseover and stay when click using jQuery.
Approach: 
First, we create an HTML div element that we want to pop up when we mouse over on an element and set its display property to none in CSS style.
display:none;
In the script tag, we create a variable flag and set its value to -1.
 $flag = -1;
Now in the script tag, we will select the element on which we want to mouseover. It is an HTML a element with class gfg. We select element a with class gfg, and then use the hover() function that is used to apply an effect when we mouse hover on an element.
We use two functions, first one executes when the mouse-enter event occurs. We select div with class popup and set its display property to block using the jQuery attr(). When the mouse-leave event occurs, the second function executes with the divs display value to none when the flag is not equal to -1.
JavaScript Code:
$("a.gfg").hover(
    function () {
        $("div.popup").attr("style", "display:block");
    },
    function () {
        if ($flag == -1) {
            $("div.popup").attr("style", "display:none");
        }
    }
);
We add a jQuery click event on element a. When we click on element a, the function sets the variable flag value to 1, so the div element stays after clicking.
$("a.gfg").click(function () {
    $flag = 1;
});
HTML Code: Below is the full implementation of the above approach.
HTML
<!DOCTYPE html><html>  <head>      <!-- JQuery CDN -->    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">    </script>      <style>        center {            font-size: 30px;            color: green;        }          .popup {            display: none;            width: 500px;            border: solid red 3px        }    </style></head>  <body>    <center>        <p>            Hover <a href="#" class="gfg">here</a>             to see the changes.        </p>          <div class="popup">            GeeksforGeeks        </div>    </center>      <script>        $flag = -1;          $("a.gfg").hover(            function () {                $("div.popup").attr("style", "display:block");            },            function () {                if ($flag == -1) {                    $("div.popup").attr("style", "display:none");                }            }        );          $("a.gfg").click(function () {            $flag = 1;        });    </script></body>  </html>
Output:
pop up mouse hover
CSS-Properties
jQuery-Methods
jQuery-Questions
Picked
CSS
HTML
JQuery
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to get the list of all the commands available in the PowerShell?

To get the list of all the commands installed in the system use the below command line. It
will include all the Alias, Functions and Cmdlets.
Get-Command
To export them into the CSV file,
Get-Command | Export-Csv D:\Temp\PowerShellcommands.csv -
NoTypeInformation
To get only the cmdlets commands,
Get-Command -CommandType Cmdlet
Similarly, you can get the commands for the alias and functions.
If you want the list of commands starting with getting, you parameter –Verb.
Get-Command -Verb Get
To get command starting with Set,
Get-Command -Verb Set
Compute the inverse of a matrix using NumPy

26 Feb, 2021
The inverse of a matrix is just a reciprocal of the matrix as we do in normal arithmetic for a single number which is used to solve the equations to find the value of unknown variables. The inverse of a matrix is that matrix which when multiplied with the original matrix will give as an identity matrix. The inverse of a matrix exists only if the matrix is non-singular i.e., determinant should not be 0. Using determinant and adjoint, we can easily find the inverse of a square matrix using below formula,
if det(A) != 0
    A-1 = adj(A)/det(A)
else
    "Inverse doesn't exist"  

where,
A-1: The inverse of matrix A
x: The unknown variable column
B: The solution matrix
We can find out the inverse of any square matrix with the function numpy.linalg.inv(array). 
Syntax: numpy.linalg.inv(a)
Parameters:
a: Matrix to be inverted
Returns: Inverse of the matrix a.
Example 1:
Python3
# Importing Libraryimport numpy as np  # Finding an inverse of given arrayarr = np.array([[1, 2], [5, 6]])inverse_array = np.linalg.inv(arr)print("Inverse array is ")print(inverse_array)print()  # inverse of 3X3 matrixarr = np.array([[1, 2, 3],                 [4, 9, 6],                 [7, 8, 9]])  inverse_array = np.linalg.inv(arr)print("Inverse array is ")print(inverse_array)print()  # inverse of 4X4 matrixarr = np.array([[1, 2, 3, 4],                 [10, 11, 14, 25],                [20, 8, 7, 55],                 [40, 41, 42, 43]])  inverse_array = np.linalg.inv(arr)print("Inverse array is ")print(inverse_array)print()  # inverse of 1X1 matrixarr = np.array([[1]])inverse_array = np.linalg.inv(arr)print("Inverse array is ")print(inverse_array)
Output:
Inverse array is 
[[-1.5   0.5 ]
 [ 1.25 -0.25]]

Inverse array is 
[[-0.6875     -0.125       0.3125    ]
 [-0.125       0.25       -0.125     ]
 [ 0.64583333 -0.125      -0.02083333]]

Inverse array is 
[[-15.07692308   4.9         -0.8         -0.42307692]
 [ 32.48717949 -10.9          1.8          1.01282051]
 [-20.84615385   7.1         -1.2         -0.65384615]
 [  3.41025641  -1.1          0.2          0.08974359]]

Inverse array is 
[[1.]]

Example 2:
Python3
# Import required package import numpy as np     # Inverses of several matrices can # be computed at once A = np.array([[[1., 2.], [3., 4.]],               [[1, 3], [3, 5]]])     # Calculating the inverse of the matrix print(np.linalg.inv(A))
Output:
[[[-2.    1.  ]
  [ 1.5  -0.5 ]]

 [[-1.25  0.75]
  [ 0.75 -0.25]]]

Python numpy-Matrix Function
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
which command in Linux with examples

27 May, 2019
which command in Linux is a command which is used to locate the executable file associated with the given command by searching it in the path environment variable. It has 3 return status as follows:
0 : If all specified commands are found and executable.
1 : If one or more specified commands is nonexistent or not executable.
2 : If an invalid option is specified.
Syntax:
which [filename1] [filename2] ...
Options:
which -a : This option print all matching pathnames of each argument.
info which : It displays help information.
linux-command
Linux-Shell-Commands
Linux-Unix
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
tar command in Linux with examples
'crontab' in Linux with Examples
Tail command in Linux with examples
Docker - COPY Instruction
UDP Server-Client implementation in C
scp command in Linux with Examples
diff command in Linux with examples
echo command in Linux with Examples
Cat command in Linux with examples
touch command in Linux with Examples
Python – seaborn.pairplot() method

15 Jul, 2020
Seaborn is a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics. Seaborn helps resolve the two major problems faced by Matplotlib; the problems are ?
Default Matplotlib parameters
Working with data frames
As Seaborn compliments and extends Matplotlib, the learning curve is quite gradual. If you know Matplotlib, you are already half way through Seaborn.
To plot multiple pairwise bivariate distributions in a dataset, you can use the pairplot() function. This shows the relationship for (n, 2) combination of variable in a DataFrame as a matrix of plots and the diagonal plots are the univariate plots.
                        seaborn.pairplot( data, \*\*kwargs )


Seaborn.pairplot uses many arguments as input, main of which are described below in form of table:
Below is the implementation of above method:
Python3
# importing packagesimport seabornimport matplotlib.pyplot as plt  ############# Main Section ############# loading dataset using seaborndf = seaborn.load_dataset('tips')# pairplot with hue sexseaborn.pairplot(df, hue ='sex')# to showplt.show()  # This code is contributed by Deepanshu Rustagi.
  
 
Python3
# importing packagesimport seabornimport matplotlib.pyplot as plt  ############# Main Section ############# loading dataset using seaborndf = seaborn.load_dataset('tips')# pairplot with hue dayseaborn.pairplot(df, hue ='day')# to showplt.show()  # This code is contributed by Deepanshu Rustagi.
  
 
Data Visualization
Python-Seaborn
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Read JSON file using Python
Adding new column to existing DataFrame in Pandas
Python map() function
How to get column names in Pandas dataframe
Python Dictionary
Different ways to create Pandas Dataframe
Taking input in Python
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
numpy.stack() in Python

06 Jan, 2019
numpy.stack() function is used to join a sequence of same dimension arrays along a new axis.The axis parameter specifies the index of the new axis in the dimensions of the result. For example, if axis=0 it will be the first dimension and if axis=-1 it will be the last dimension.
Syntax : numpy.stack(arrays, axis)
Parameters :arrays : [array_like] Sequence of arrays of the same shape.axis : [int] Axis in the resultant array along which the input arrays are stacked.
Return : [stacked ndarray] The stacked array of the input arrays which has one more dimension than the input arrays.
Code #1 :
# Python program explaining# stack() function  import numpy as geek  # input arrayin_arr1 = geek.array([ 1, 2, 3] )print ("1st Input array : \n", in_arr1)   in_arr2 = geek.array([ 4, 5, 6] )print ("2nd Input array : \n", in_arr2)   # Stacking the two arrays along axis 0out_arr1 = geek.stack((in_arr1, in_arr2), axis = 0)print ("Output stacked array along axis 0:\n ", out_arr1)  # Stacking the two arrays along axis 1out_arr2 = geek.stack((in_arr1, in_arr2), axis = 1)print ("Output stacked array along axis 1:\n ", out_arr2)
1st Input array : 
 [1 2 3]
2nd Input array : 
 [4 5 6]
Output stacked array along axis 0:
  [[1 2 3]
 [4 5 6]]
Output stacked array along axis 1:
  [[1 4]
 [2 5]
 [3 6]]

 Code #2 :
# Python program explaining# stack() function  import numpy as geek  # input arrayin_arr1 = geek.array([[ 1, 2, 3], [ -1, -2, -3]] )print ("1st Input array : \n", in_arr1)   in_arr2 = geek.array([[ 4, 5, 6], [ -4, -5, -6]] )print ("2nd Input array : \n", in_arr2)   # Stacking the two arrays along axis 0out_arr1 = geek.stack((in_arr1, in_arr2), axis = 0)print ("Output stacked array along axis 0:\n ", out_arr1)  # Stacking the two arrays along axis 1out_arr2 = geek.stack((in_arr1, in_arr2), axis = 1)print ("Output stacked array along axis 1:\n ", out_arr2)  # Stacking the two arrays along last axis out_arr3 = geek.stack((in_arr1, in_arr2), axis = -1)print ("Output stacked array along last axis :\n ", out_arr3)
1st Input array : 
 [[ 1  2  3]
 [-1 -2 -3]]
2nd Input array : 
 [[ 4  5  6]
 [-4 -5 -6]]
Output stacked array along axis 0:
  [[[ 1  2  3]
  [-1 -2 -3]]

 [[ 4  5  6]
  [-4 -5 -6]]]
Output stacked array along axis 1:
  [[[ 1  2  3]
  [ 4  5  6]]

 [[-1 -2 -3]
  [-4 -5 -6]]]
Output stacked array along last axis :
  [[[ 1  4]
  [ 2  5]
  [ 3  6]]

 [[-1 -4]
  [-2 -5]
  [-3 -6]]]

Python numpy-arrayManipulation
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Drop the Index Column in Pandas?

28 Nov, 2021
In this article, we will discuss how to drop the index column in pandas using Python.
First we have to create the dataframe with student details and set the index by using set_index() function
Syntax:
dataframe.set_index([pandas.Index([index_values.......])])
where
dataframe is the input dataframe
Index_values are the values to be given as indexes to the dataframe
Example: Setting index column for the dataset. The initial plot does that the changes are apparent.
Python3
# import pandas moduleimport pandas as pd  # create dataframe with 3 columnsdata = pd.DataFrame({    "id": [7058, 7059, 7072, 7054],    "name": ['sravan', 'jyothika', 'harsha', 'ramya'],    "subjects": ['java', 'python', 'html/php', 'php/js']})  # set the index valuesdata = data.set_index(    [pd.Index(['student-1', 'student-2', 'student-3', 'student-4'])])  # display dataframeprint(data)
Output:
Now we can drop the index columns by using reset_index() method. It will remove the index values and set the default values from 0 to n values
Syntax:
dataframe.reset_index(drop=True, inplace=True)
where
dataframe is the input dataframe
drop is set to True to remove index values
inplace is to set the default integers
Example: Drop the index columns
Python3
# import pandas moduleimport pandas as pd  # create dataframe with 3 columnsdata = pd.DataFrame({    "id": [7058, 7059, 7072, 7054],    "name": ['sravan', 'jyothika', 'harsha', 'ramya'],    "subjects": ['java', 'python', 'html/php', 'php/js']})  # set the index valuesdata = data.set_index(    [pd.Index(['student-1', 'student-2', 'student-3', 'student-4'])])  # display dataframeprint(data)    # drop the index columnsdata.reset_index(drop=True, inplace=True)  # displayprint(data)
Output:
pandas-dataframe-program
Picked
Python pandas-dataFrame
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
Python | os.path.join() method
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Get unique values from a list
Python | datetime.timedelta() function
C# Program to count the number of lines in a file

Firstly, create a file using StreamWriter class and add content to it −
using (StreamWriter sw = new StreamWriter("hello.txt")) {
   sw.WriteLine("This is demo line 1");
   sw.WriteLine("This is demo line 2");
   sw.WriteLine("This is demo line 3");
}
Now use the ReadAllLines() method to read all the lines. With that, the Length property is to be used to get the count of lines −
int count = File.ReadAllLines("hello.txt").Length;
Here is the complete code −
 Live Demo
using System;
using System.Collections.Generic;
using System.IO;
public class Program {
   public static void Main() {
      using (StreamWriter sw = new StreamWriter("hello.txt")) {
         sw.WriteLine("This is demo line 1");
         sw.WriteLine("This is demo line 2");
         sw.WriteLine("This is demo line 3");
      }
      int count = File.ReadAllLines("hello.txt").Length;
      Console.WriteLine("Number of lines: "+count);
   }
}
Number of lines: 3
HTML <img> Tag

27 Aug, 2021
HTML <img> tag is used to add image inside webpage/website. Nowadays website does not directly add images to a web page, as the images are linked to web pages by using the <img> tag which holds space for the image.
Syntax:  
<img src="" alt="" width="" height="">
Attributes: The <img> tag has following attributes.
 
src: It is used to specify the path to the image.
alt: It is used to specify an alternate text for the image. It is useful as it informs the user about what the image means and also due to any network issue if the image cannot be displayed then this alternate text will be displayed.
crossorigin: It is used to import images from third-party sites that allow cross-origin access to be used with canvas.
height: It is used to specify the height of the image.
width: It is used to specify the width of the image.
ismap: It is used to specify an image as a server-side image map.
loading: It is used to specify whether a browser should defer loading of images until some conditions are met or load an image immediately.
longdesc: It is used to specify a URL to a detailed description of an image.
referrerpolicy: It is used to specify which referrer information to use when fetching an image i.e. no-referrer, no-referrer-when-downgrade, origin, origin-when-cross-origin, unsafe-url.
sizes: It is used to specify image sizes for different page layouts.
srcset: It is used to specify a list of image files to use in different situations.
usemap: It is used to specify an image as a client-side image map.
 
Example 1: In this example we are using the <img> tag along with src, width, height, and alt attributes.
 
HTML
<!DOCTYPE html><html>  <body style="text-align: center;">    <h3>GeeksforGeeks logo</h3>          <img src="https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png"        width="420" height="100"         alt="Geeksforgeeks.org"></body>  </html>
Output:
img src with width and height
Example 2: In this example, we are adding the style attribute to add a border to the image.
HTML
<!DOCTYPE html><html>  <body style="text-align: center;">    <h3>GeeksforGeeks logo</h3>      <img src="https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png"        width="420" height="100"         alt="Geeksforgeeks.org"         style="border:5px solid black"></body>  </html>
Output:
image source with border
Supported Browsers: 
Google Chrome
Internet Explorer
Safari
Opera
firefox
hritikbhatnagar2182
HTML-Attributes
HTML-Tags
Picked
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
UGC-NET | UGC NET CS 2017 Jan – II | Question 1

26 Mar, 2018
Consider a sequence F00 defined as :F00(0) = 1, F00(1) = 1F00(n) = 10 ∗ F00(n – 1) + 100F00(n – 2) for n ≥ 2Then what shall be the set of values of the sequence F00 ?(A) (1, 110, 1200)(B) (1, 110, 600, 1200)(C) (1, 2, 55, 110, 600, 1200)(D) (1, 55, 110, 600, 1200)Answer: (A)Explanation:
 F00(0) = 1, F00(1) = 1
 F00(n) = 10 ∗ F00(n – 1) + 100
 F00(2) = 10 * F00(1) + 100
 = 10 * 1 + 100
 = 10 + 100
 = 110
Similarly:
F00(3) = 10 * F00(2) + 100
 = 10 * 110 + 100
 = 1100 + 100
 = 1200
The sequence will be (1, 110, 1200).
So, (A) will be the answer.Quiz of this Question
UGC-NET
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
UGC-NET | UGC NET CS 2018 July - II | Question 23
UGC-NET | UGC NET CS 2015 Jun - III | Question 35
UGC-NET | UGC NET CS 2015 Jun - III | Question 32
UGC-NET | UGC NET CS 2015 Jun - III | Question 33
UGC-NET | UGC NET CS 2016 Aug - III | Question 32
UGC-NET | UGC NET CS 2015 Jun - III | Question 64
UGC-NET | UGC NET CS 2015 Dec - II | Question 16
UGC-NET | UGC NET CS 2016 July – II | Question 22
UGC-NET | UGC NET CS 2014 Dec - II | Question 35
UGC-NET | UGC NET CS 2015 Jun - III | Question 31
JavaScript | Redirect a URL

19 Feb, 2019
Prerequisites:
Learn Basic HTML
Learn Basic Javascript
Redirecting a URL in JavaScript is nothing but sending the user from a URL to another URL. In Javascript, window.location function is used to redirect to a URL.
<!DOCTYPE html><html><head>    <title>Redirect url in Javascript</title></head><body><script>    var url= "https://www.geeksforgeeks.org";    window.location = url;</script></body></html>
Output:
Code #2:Below code takes an input url from the user and the url is stored in a variable through getElementById() and window.location takes the page to that url.
<!DOCTYPE html><html><head>    <title>Redirect url in Javascript</title></head><body><input id = "url" type = "text" name = "url"                         placeholder = "Enter a url here"><input type = "submit" name = "button" onclick = "fun()"><script>function fun() {    var url= document.getElementById("url").value;    document.write("Redirecting to the url in 3 seconds...");    setTimeout(function(){window.location = url;}, 3000);}</script></body></html>
Output:At first this will be the output, and then if the link like (https://www.geeksforgeeks.org/) is put inside the box, it will redirect to the home page of the GeeksforGeeks and will be shown like below.
Steps for executing above codes:
Save these files with .html extension as file_name.html
Then open the files in a browser, it will get redirect to the GeeksforGeeks homepage.
JavaScript-Misc
HTML
JavaScript
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
JSP - Lifecycle

In this chapter, we will discuss the lifecycle of JSP. The key to understanding the low-level functionality of JSP is to understand the simple life cycle they follow.
A JSP life cycle is defined as the process from its creation till the destruction. This is similar to a servlet life cycle with an additional step which is required to compile a JSP into servlet.
The following are the paths followed by a JSP −
Compilation
Initialization
Execution
Cleanup
The four major phases of a JSP life cycle are very similar to the Servlet Life Cycle. The four phases have been described below −
When a browser asks for a JSP, the JSP engine first checks to see whether it needs to compile the page. If the page has never been compiled, or if the JSP has been modified since it was last compiled, the JSP engine compiles the page.
The compilation process involves three steps −
Parsing the JSP.
Turning the JSP into a servlet.
Compiling the servlet.
When a container loads a JSP it invokes the jspInit() method before servicing any requests. If you need to perform JSP-specific initialization, override the jspInit() method −
public void jspInit(){
   // Initialization code...
}
Typically, initialization is performed only once and as with the servlet init method, you generally initialize database connections, open files, and create lookup tables in the jspInit method.
This phase of the JSP life cycle represents all interactions with requests until the JSP is destroyed.
Whenever a browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes the _jspService() method in the JSP.
The _jspService() method takes an HttpServletRequest and an HttpServletResponse as its parameters as follows −
void _jspService(HttpServletRequest request, HttpServletResponse response) {
   // Service handling code...
}
The _jspService() method of a JSP is invoked on request basis. This is responsible for generating the response for that request and this method is also responsible for generating responses to all seven of the HTTP methods, i.e, GET, POST, DELETE, etc.
The destruction phase of the JSP life cycle represents when a JSP is being removed from use by a container.
The jspDestroy() method is the JSP equivalent of the destroy method for servlets. Override jspDestroy when you need to perform any cleanup, such as releasing database connections or closing open files.
The jspDestroy() method has the following form −
public void jspDestroy() {
   // Your cleanup code goes here.
}

    108 Lectures 
     11 hours 

 Chaand Sheikh

    517 Lectures 
     57 hours 

 Chaand Sheikh

    41 Lectures 
     4.5 hours 

 Karthikeya T

    42 Lectures 
     5.5 hours 

 TELCOMA Global

    15 Lectures 
     3 hours 

 TELCOMA Global

    44 Lectures 
     15 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page
Tryit Editor v3.6 - Show Python

f = open("D:\\myfiles\welcome.txt", "r")
PHP date_time_set() Function

The date_time_set() function is an alias of the DateTime::setTime() function. Using this, you can (re)set the time of a DateTime object.
date_time_set($object, $hours, $minutes, $seconds, $microseconds)

object(Mandatory)
This is a DateTime object to which you need to set the date.
hours(Mandatory)
This is an integer value representing the hour of the time to be set.
minute(Mandatory)
This is an integer value representing the minute of the time to be set.
seconds(Optional)
This is an integer value representing the seconds of the time to be set.
microseconds(Optional)
This is an integer value representing the microseconds of the time to be set.
PHP date_time_set() function returns the DateTime object with modified (time) value. Incase of failure, this function returns the boolean value false.
This function was first introduced in PHP Version 5.2.0 and, works with all the later versions.
Following example demonstrates the usage of the date_time_set function −
<?php
   //Creating a date
   $date = new DateTime();
   //Setting the date
   date_time_set($date, 7, 20, 35);   
   print("Date: ".date_format($date, "Y/m/d H:i:s"));
?>
This will produce following result −
Date: 2020/05/10 07:20:35
Following example creates a DateTime object and modifies its t using the date_time_set() function. −
<?php
   //Date string
   $date_string = "25-09-1989 10:42:12";
   //Creating a DateTime object
   $date_time_Obj = date_create($date_string);
   print("Original Date: ".date_format($date_time_Obj, "Y/m/d H:i:s"));
   print("\n");
   //Setting the date
   $date = date_time_set($date_time_Obj, 6, 36, 3 );   
   print("Modified Date: ".date_format($date, "Y/m/d H:i:s"));
?>
This will produce following result −
Original Date: 1989/09/25 10:42:12
Modified Date: 1989/09/25 06:36:03

While invoking this function if you pass the day and month values exceeding their range, they will be added to their parent values −
<?php
   //Creating a date
   $date = new DateTime();
   //Setting the date
   date_time_set($date, 24, 15, 36);   
   print("Date: ".date_format($date, "Y/m/d H:i:s"));
?>
Since we have set the month value as 15. Three months are added to the appropriate time −
Date: 2020/05/11 00:15:36

$dateSrc = '2007-04-19 12:50 GMT';
$dateTime = date_create( $dateSrc);;
$retval = date_time_set( $dateTime, 20, 40, 10);
   
echo 'DateTime::format(): '.$dateTime->format('Y:M:D:H:i:s');
echo "\n";

# Using second function.
$dateTime = new DateTime($dateSrc);
$retval = $dateTime->setTime(20, 56,6);
   
echo 'DateTime::format(): '.$dateTime->format('Y:M:D:H:i:s');
This will produce the following result −
DateTime::format(): 2007:Apr:Thu:20:40:10
DateTime::format(): 2007:Apr:Thu:20:56:06


    45 Lectures 
     9 hours 

 Malhar Lathkar

    34 Lectures 
     4 hours 

 Syed Raza

    84 Lectures 
     5.5 hours 

 Frahaan Hussain

    17 Lectures 
     1 hours 

 Nivedita Jain

    100 Lectures 
     34 hours 

 Azaz Patel

    43 Lectures 
     5.5 hours 

 Vijay Kumar Parvatha Reddy
 Print
 Add Notes
 Bookmark this page
Grouping objects based on key property in JavaScript

We have a parentArray that contains many sub arrays each of the same size, each sub array is
an array of objects containing two properties: key and value. Within a subarray it is confirmed
that two objects cannot have the same key but all subarrays have the same pair of n keys
where n is the size of the sub array.
Our job is to prepare an object with key as key of objects and value being an array that contains all the values for that particular key.
Here is a sample parent array −
const parentArray = [[
{
   key: 123,
   value: 'India'
}, {
   key: 124,
   value: 'USA'
}, {
   key: 125,
   value: 'Japan'
}, {
   key: 126,
   value: 'Denmark'
}, {
   key: 127,
   value: 'Austria'
},
], [
{
   key: 124,
   value: 'Kenya'
}, {
   key: 126,
   value: 'UK'
}, {
   key: 123,
   value: 'Germany'
}, {
   key: 127,
   value: 'Spain'
}, {
   key: 125,
   value: 'Portugal'
},
]];
We will iterate over the parent array and then all of the sub arrays one by one and if we find a matching key, we push it into the value array otherwise we create a new value array.
The full code for this will be −
const parentArray = [[
{
   key: 123,
   value: 'India'
}, {
   key: 124,
   value: 'USA'
}, {
   key: 125,
   value: 'Japan'
}, {
   key: 126,
   value: 'Denmark'
}, {
   key: 127,
   value: 'Austria'
},
], [
{
   key: 124,
   value: 'Kenya'
}, {
   key: 126,
   value: 'UK'
}, {
   key: 123,
   value: 'Germany'
}, {
   key: 127,
   value: 'Spain'
}, {
   key: 125,
   value: 'Portugal'
},
]];
const map = {};
parentArray.forEach(arr => {
   arr.forEach(obj => {
      const { key, value } = obj;
      if(map[key]){
         map[key].push(value);
      }else{
         map[key] = [value]
      }
   })
});
console.log(map);
The output in the console will be −
{
   '123': [ 'India', 'Germany' ],
   '124': [ 'USA', 'Kenya' ],
   '125': [ 'Japan', 'Portugal' ],
   '126': [ 'Denmark', 'UK' ],
   '127': [ 'Austria', 'Spain' ]
}
IntStream range() method in Java

The range() method in the IntStream class in Java is used to return a sequential ordered IntStream from startInclusive to endExclusive by an incremental step of 1. This includes the startInclusive as well.
The syntax is as follows −
static IntStream range(int startInclusive, int endExclusive)
Here, the parameter startInclusive includes the starting value, whereas endExclusive excludes the last value
To work with the IntStream class in Java, import the following package −
import java.util.stream.IntStream;
Create an IntStream and add stream elements in a range using range() method. This returns a sequential ordered IntStream by an incremental step of 1 within the range −
intStream.forEach(System.out::println);
The following is an example to implement IntStream range() method in Java −
 Live Demo
import java.util.*;
import java.util.stream.IntStream;

public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.range(20, 30);
      intStream.forEach(System.out::println);
   }
}
20
21
22
23
24
25
26
27
28
29
Python Pandas - Indicate all duplicate index values as True

To indicate all duplicate index values as True, use the index.duplicated(). Use the keep parameter with the value False.
At first, import the required libraries −
import pandas as pd
Creating the index with some duplicates −
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])
Display the index −
print("Pandas Index with duplicates...\n",index)
Indicate all duplicate index values as True. Set the "keep" parameter as "False" −
print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False))
Following is the code −
import pandas as pd

# Creating the index with some duplicates
index = pd.Index(['Car','Bike','Airplane','Ship','Airplane'])

# Display the index
print("Pandas Index with duplicates...\n",index)

# Return the dtype of the data
print("\nThe dtype object...\n",index.dtype)

# get the dimensions of the data
print("\nGet the dimensions...\n",index.ndim)

# Indicate all duplicate index values as True
# Set the "keep" parameter as "False"
print("\nIndicating all duplicate index values True...\n", index.duplicated(keep=False))
This will produce the following code −
Pandas Index with duplicates...
Index(['Car', 'Bike', 'Airplane', 'Ship', 'Airplane'], dtype='object')

The dtype object...
object

Get the dimensions...
1

Indicating all duplicate index values True...
[False False True False True]
Write a program to find the first non-repeating number in an integer array using Java?

To find the first non-repeating number in an array −
Construct count array to store count of each element in the given array with same length and with initial value 0 for all elements.
Compare each element in the array with all other elements, except itself.
If match occurs increment its value in the count array.
Get the index of the first 0 in the count array and print the element in the input array at this index.
import java.util.Arrays;
public class NonRpeatingArray {
   public static void main(String args[]) {
      int array[] = {114, 225, 669, 996, 336, 6547, 669, 225, 336, 669, 996, 669, 225 };
      System.out.println("");
      //Creating the count array
      int countArray[] = new int[array.length];
      for(int i=0; i<array.length; i++) {
         countArray[i] = 0;
      }
      for(int i=0; i<array.length; i++) {
         for(int j=0; j<array.length;j++) {
            if(i!=j && array[i]==array[j]) {
               countArray[i]++;
            }
         }
      }
      System.out.println(Arrays.toString(countArray));
      //First non-repeating element in the array
      for(int i=0; i<array.length; i++) {
         if(countArray[i]==0) {
            System.out.println(array[i]);
            break;
         }
      }
   }
}
[0, 2, 3, 1, 1, 0, 3, 2, 1, 3, 1, 3, 2]
114
How to add display:none in an HTML element using jQuery?

To workaround with display: none in an element in jQuery, use the hide() method. It will do the same work.
You can try to run the following code to learn how to add display:none in an HTML element −
Live Demo
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").removeAttr("style").hide();
  });
});
</script>
</head>
<body>

<h1>Heading 1</h1>

<p style="font-size:15px">This is demo text. This will hide on button click.</p>
<p>This is another text. This will hide on button click</p>

<button>Hide</button>

</body>
</html>
How to upsample a matrix by repeating elements using NumPy in Python?

03 Jan, 2021
Prerequisites: Numpy
Upsampling a matrix simply means expanding it and obviously upsampling can be done by adding more elements to the original matrix. It can be done in various ways like adding new elements and expanding the original matrix or it can be done by the matrix elements of original matrix itself. The later approach is discussed below along with 2 methods to do the same.
We use the numpy.repeat() method to upsample the matrix by repeating the numbers of the matrix. We pass the matrix in repeat() method with the axis to upsample the matrix. This method is used to repeat elements of array.
Syntax:   
numpy.repeat(array, repeats, axis=0)
Parameters:
array=Name of the array
repeats= Numbers of repetitions of every element
axis= The axis along which to repeat the values. By default, axis is set to None.
For row-wise axis=0 and for column-wise axis=1.
Approach
Import module
Create array
Pass it to repeat method
Print matrix
Example:
Python3
# importing required moduleimport numpy as np  # declaring an arraya = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]  # use the repeat function to upsample the arrayprint(np.repeat(a, 5, axis=1).repeat(3, axis=0))
Output:
In this approach we will see how np.kron is used to upsample a matrix. We pass the matrix along with an ones matrix which will multiply with each other using kron() method and the result will be an upsampled matrix.
Syntax:
np.kron(a ,b)
where a and b are two arrays.
It returns the Kronecker product of two arrays.
Its parameters are two arrays whose product to be calculated
Example: 
Python3
# import required librariesimport numpy as np  # creating an array using numpya = np.array([[9, 8, 5], [11, 12, 14], [20, 21, 22]])  # using kron function upsampling the arrayupsampled_array = np.kron(a, np.ones((2, 2)))  # printing the desired resultprint(upsampled_array)
Output :
Picked
Python numpy-Matrix Function
Python-numpy
Technical Scripter 2020
Python
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
Python | os.path.join() method
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Get unique values from a list
Create a directory in Python