
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 26504 Articles for Server Side Programming

171 Views
To compute first of group values, use the groupby.first() method. At first, import the required library with an alias −import pandas as pd;Create a DataFrame with 3 columns −dataFrame = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'BMW', 'Tesla', 'Lexus', 'Tesla'], "Place": ['Delhi', 'Bangalore', 'Pune', 'Punjab', 'Chandigarh', 'Mumbai'], "Units": [100, 150, 50, 80, 110, 90] } )Now, group DataFrame by a column −groupDF = dataFrame.groupby("Car") Compute first of group values and resetting index −res = groupDF.first() res = res.reset_index()ExampleFollowing is the complete code − import pandas as pd; dataFrame = pd.DataFrame( { ... Read More

400 Views
To extract the value names and counts, let us first create a DataFrame with 4 columns −dataFrame = pd.DataFrame({"Car": ['BMW', 'Mustang', 'Tesla', 'Mustang', 'Mercedes', 'Tesla', 'Audi'], "Cubic Capacity": [2000, 1800, 1500, 2500, 2200, 3000, 2000], "Reg Price": [7000, 1500, 5000, 8000, 9000, 6000, 1500], "Units Sold": [ 200, 120, 150, 120, 210, 250, 220] })Fetch the value names and count for a specific column Car −res = dataFrame['Car'].value_counts() Fetch the value names and count for a specific column Units Sold −res = dataFrame['Units Sold'].value_counts()ExampleFollowing is the complete code −import pandas as pd # creating dataframe dataFrame = pd.DataFrame({"Car": ['BMW', ... Read More

3K+ Views
To merge Pandas DataFrame, use the merge() function. The one-to-many relation is implemented on both the DataFrames by setting under the “validate” parameter of the merge() function i.e. −validate = “one-to-many” or validate = “1:m”The one-to-many relation checks if merge keys are unique in left dataset.At first, let us create our 1st DataFrame −dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Now, let us create our 2nd DataFrame −dataFrame2 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Tesla', 'Mustang', 'Mercedes', ... Read More

2K+ Views
To merge Pandas DataFrame, use the merge() function. The cartesian product is implemented on both the DataFrames by setting under the “how” parameter of the merge() function i.e. −how = “cross”At first, let us import the pandas library with an alias −import pandas as pd Create DataFrame1 −dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 120] } )Create DataFrame2dataFrame2 = pd.DataFrame( { "Car": ['BMW', 'Tesla', 'Jaguar'], "Reg_Price": [7000, 8000, 9000] } )Next, merge DataFrames with "cross" in "how" parameter i.e. ... Read More

866 Views
To merge two Pandas DataFrame with common column, use the merge() function and set the ON parameter as the column name. To set NaN for unmatched values, use the “how” parameter and set it left or right. That would mean, merging left or right.At first, let us import the pandas library with an alias −import pandas as pdLet us create DataFrame1 −dataFrame1 = pd.DataFrame( { "Car": ['BMW', 'Lexus', 'Audi', 'Mustang', 'Bentley', 'Jaguar'], "Units": [100, 150, 110, 80, 110, 90] } )Let us create DataFrame2dataFrame2 = pd.DataFrame( { "Car": ['BMW', ... Read More

688 Views
To create Multiindex from DataFrame, use the MultiIndex. from_frame() method. At first, let us create a Dictionary of lists −d = {'Car': ['BMW', 'Lexus', 'Audi', 'Mercedes', 'Jaguar', 'Bentley'], 'Date_of_purchase': ['2020-10-10', '2020-10-12', '2020-10-17', '2020-10-16', '2020-10-19', '2020-10-22'] }Next, create a Pandas DataFrame from the above dictionary of lists −dataFrame = pd.DataFrame(d)Now create multiindex using from_frame() −print(pd.MultiIndex.from_frame(dataFrame))ExampleFollowing is the code −import pandas as pd # dictionary of lists d = {'Car': ['BMW', 'Lexus', 'Audi', 'Mercedes', 'Jaguar', 'Bentley'], 'Date_of_purchase': ['2020-10-10', '2020-10-12', '2020-10-17', '2020-10-16', '2020-10-19', '2020-10-22']} # creating dataframe from the above dictionary of lists dataFrame = pd.DataFrame(d) print("DataFrame...", dataFrame) # creating ... Read More

6K+ Views
The notnull() method returns a Boolean value i.e. if the DataFrame is having null value(s), then False is returned, else True.Let’s say the following is our CSV file with some NaN i.e. null values −Let us first read the CSV file −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")Checking for not null values −res = dataFrame.notnull()Now, on displaying the DataFrame, the CSV data will be displayed in the form of True and False i.e. boolean values because notnull() returns boolean. For Null values, False will get displayed. For Not-Null values, True will get displayed.ExampleFollowing is the complete code −import pandas as pd # reading ... Read More

2K+ Views
To drop the null rows in a Pandas DataFrame, use the dropna() method. Let’s say the following is our CSV file with some NaN i.e. null values −Let us read the CSV file using read_csv(). Our CSV is on the Desktop −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")Remove the null values using dropna() −dataFrame = dataFrame.dropna() ExampleFollowing is the complete code −import pandas as pd # reading csv file dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv") print("DataFrame...", dataFrame) # count the rows and columns in a DataFrame print("Number of rows and column in our DataFrame = ", dataFrame.shape) dataFrame = dataFrame.dropna() print("DataFrame after removing null ... Read More

6K+ Views
To skip initial space from a Pandas DataFrame, use the skipinitialspace parameter of the read_csv() method. Set the parameter to True to remove extra space.Let’s say the following is our csv file −We should get the following output i.e. skipping initial whitespace and displaying the DataFrame from the CSV −ExampleFollowing is the complete code −import pandas as pd # reading csv file dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv") print("DataFrame...", dataFrame) # reading csv file and removing initial space dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv", skipinitialspace = True) print("DataFrame...", dataFrame)At first, read the CSV. Our CSV file is on the Desktop −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")While reading, ... Read More

460 Views
To plot swarm plot on top of box plot, at first, set boxplot() and then the swarmplot() with the same x and y values. Box Plot in Seaborn is used to draw a box plot to show distributions with respect to categories. The seaborn.boxplot() is used for this.Swarm Plot in Seaborn is used to draw a categorical scatterplot with non-overlapping points. The seaborn.swarmplot() is used for this.Let’s say the following is our dataset in the form of a CSV file − Cricketers.csvAt first, import the required libraries −import seaborn as sb import pandas as pd import matplotlib.pyplot as pltLoad data from ... Read More