Programming Articles

Page 1109 of 2547

How to sort multiple columns of a Pandas DataFrame?

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 1K+ Views

To sort multiple columns of a Pandas DataFrame, we can use the sort_values() method.StepsCreate a two-dimensional, size-mutable, potentially heterogeneous tabular data, df.Print the input DataFrame, df.Initialize a variable col to sort the column.Print the sorted DataFrame.Exampleimport pandas as pd df = pd.DataFrame(    {       "x": [5, 2, 7, 0],       "y": [4, 7, 5, 1],       "z": [9, 3, 5, 1]    } ) print "Input DataFrame is:", df col = ["x", "y"] df = df.sort_values(col, ascending=[False, True]) print "After sorting column ", col, "DataFrame is:", dfOutputInput DataFrame is:    x  y  z 0  5  4  9 1  2  7  3 2  7  5  5 3  0  1  1 After sorting column ['x', 'y'] DataFrame is:    x  y  z 2  7  5  5 0  5  4  9 1  2  7  3 3  0  1  1

Read More

How to create stacked bar chart using ggvis in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 259 Views

To create stacked bar chart using ggvis, we can follow the below steps −First of all, create a data frame.Create the stacked bar chart with layer_bars function of ggvis package.Create the data frameLet's create a data frame as shown below −Group

Read More

How to create scatterplot for categories with grey color palette using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 310 Views

To create scatterplot for categories with grey color palette using ggplot2, we can follow the below steps −First of all, create a data frame.Then, create the scatterplot for categories with default color of points.Create the scatterplot for categories with color of points in grey palette.Create the data frameLet's create a data frame as shown below −x

Read More

How to create boxplot for categories with grey color palette using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To create boxplot for categories with grey color palette using ggplot2, we can follow the below steps −First of all, create a data frame.Then, create the boxplot for categories with default color of bars.Create the boxplot for categories with color of bars in grey palette.Create the data frameLet's create a data frame as shown below −Group

Read More

How to subset a named vector based on names in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 923 Views

To subset a named vector based on names, we can follow the below steps −Create a named vector.Subset the vector using grepl.Create the named vectorLet’s create a name vector as shown below −V

Read More

How to set the number of digits to be printed for summary command without using options(digits) in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 294 Views

To set the nuber of digits to be printed for summary command without using options(digits), we can use digits argument while printing the summary. −Example 1Using mtcars data and finding the summary statistics with number of digits set to 2 −summary(mtcars, digits=2)On executing, the above script generates the below output(this output will vary on your system due to randomization) −Output   mpg             cyl            disp            hp          drat Min.   :10    Min.   :4.0    Min.   : 71    Min.   ...

Read More

How to check if a column is categorical in R data frame?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 4K+ Views

To check if a column is categorical in R data frame, we can follow the below steps −First of all, create a data frame.Use class function to check the class of the column.Create the data frameLet's create a data frame as shown below −x

Read More

How to find the common elements in multiple vectors in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 975 Views

To find the common elements in multiple vectors, we can follow the below steps −First of all, create a number of vectors.Use intersect function to find the common elements in all the vectors.Create the vectorsLet’s create a number of vectors as shown below −x

Read More

How to find the unique elements in multiple vectors in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 1K+ Views

To find the unique elements in multiple vectors, we can follow the below steps −First of all, create a number of vectors.Use setdiff function to find the common elements in all the vectors.Create the vectorsLet’s create a number of vectors as shown below −x

Read More

How to find the starting position for consecutive values given the length of consecutive values in an R vector?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 839 Views

To find the starting position for consecutive values given the length of consecutive values in an R vector, we can follow the below steps −First of all, create a vector with duplicated values.Find the run length.Create a vector with FALSE of vector size.Find the starting position by setting running length of consecutive values to TRUE for given length.Create the vectorLet’s create a vector having many duplciates so that we can get same consecutive values −x

Read More
Showing 11081–11090 of 25,466 articles
Advertisements