Pandas Articles

Page 42 of 42

Write a program in Python to check if a series contains duplicate elements or not

Vani Nalliappan
Vani Nalliappan
Updated on 24-Feb-2021 195 Views

Input − Assume, you have the following series, 0    1 1    2 2    3 3    4 4    5The above series contains no duplicate elements. Let’s verify using the following approaches.Solution 1Assume, you have a series with duplicate elements0    1 1    2 2    3 3    4 4    5 5    3Set if condition to check the length of the series is equal to the unique array series length or not. It is defined below, if(len(data)==len(np.unique(data))):    print("no duplicates") else:    print("duplicates found")Exampleimport pandas as pd import numpy as np data = ...

Read More

Python Pandas - Read data from a CSV file and print the ‘product’ column value that matches ‘Car’ for the first ten rows

Vani Nalliappan
Vani Nalliappan
Updated on 17-Feb-2021 972 Views

Assume, you have ‘products.csv’ file and the result for a number of rows and columns and ‘product’ column value matches ‘Car’ for the first ten rows are −Download the products.csv file here.Rows: 100 Columns: 8 id    product    engine    avgmileage    price    height_mm    width_mm    productionYear 1 2    Car       Diesel       21         16500       1530          1735         2020 4 5    Car         Gas        18         17450   ...

Read More

How to select subsets of data In SQL Query Style in Pandas?

Kiran P
Kiran P
Updated on 10-Nov-2020 406 Views

IntroductionIn this post, I will show you how to perform Data Analysis with SQL style filtering with Pandas. Most of the corporate company’s data are stored in databases that require SQL to retrieve and manipulate it. For instance, there are companies like Oracle, IBM, Microsoft having their own databases with their own SQL implementations.Data scientists have to deal with SQL at some stage of their career as the data is not always stored in CSV files. I personally prefer to use Oracle, as the majority of my company’s data is stored in Oracle.Scenario – 1 Suppose we are given a ...

Read More

How to select subset of data with Index Labels in Python Pandas?

Kiran P
Kiran P
Updated on 10-Nov-2020 2K+ Views

IntroductionPandas have a dual selection capability to select the subset of data using the Index position or by using the Index labels. Inthis post, I will show you how to “Select a Subset Of Data Using Index Labels” using the index label.Remember, Python dictionaries and lists are built-in data structures that select their data either by using the index label or byindex position. A dictionary’s key must be a string, integer, or tuple while a List must either use integers (the position) or sliceobjects for selection.Pandas have .loc and.iloc attributes available to perform index operations in their own unique ways. ...

Read More

How to Handle Large CSV files with Pandas?

Sasanka Chitrakavi
Sasanka Chitrakavi
Updated on 23-Oct-2020 2K+ Views

In this post, we will go through the options handling large CSV files with Pandas.CSV files are common containers of data, If you have a large CSV file that you want to process with pandas effectively, you have a few options.Pandas is an in−memory toolYou need to be able to fit your data in memory to use pandas with it. If you can process portions of it at a time, you can read it into chunks and process each chunk. Alternatively, if you know that you should have enough memory to load the file, there are a few hints to ...

Read More

Accessing elements of a Pandas Series

Pradeep Elance
Pradeep Elance
Updated on 30-Jun-2020 11K+ Views

Pandas series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). The elements of a pandas series can be accessed using various methods.Let's first create a pandas series and then access it's elements.Creating Pandas SeriesA panadas series is created by supplying data in various forms like ndarray, list, constants and the index values which must be unique and hashable. An example is given below.Exampleimport pandas as pd s = pd.Series([11, 8, 6, 14, 25], index = ['a', 'b', 'c', 'd', 'e']) print sOutputRunning the above code gives us the following result ...

Read More

Add new column in Pandas Data Frame Using a Dictionary

Pradeep Elance
Pradeep Elance
Updated on 30-Jun-2020 1K+ Views

Pandas Data Frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. It can be created using python dict, list, and series etc. In this article, we will see how to add a new column to an existing data frame.So first let's create a data frame using pandas series. In the below example we are converting a pandas series to a Data Frame of one column, giving it a column name Month_no.Exampleimport pandas as pd s = pd.Series([6, 8, 3, 1, 12]) df = pd.DataFrame(s, columns=['Month_No']) print (df)OutputRunning the above code gives ...

Read More

Boolean Indexing in Pandas

Hafeezul Kareem
Hafeezul Kareem
Updated on 02-Jan-2020 2K+ Views

Boolean indexing helps us to select the data from the DataFrames using a boolean vector. We need a DataFrame with a boolean index to use the boolean indexing. Let's see how to achieve the boolean indexing.Create a dictionary of data.Convert it into a DataFrame object with a boolean index as a vector.Now, access the data using boolean indexing.See the example below to get an idea.Exampleimport pandas as pd # data data = {    'Name': ['Hafeez', 'Srikanth', 'Rakesh'],    'Age': [19, 20, 19] } # creating a DataFrame with boolean index vector data_frame = pd.DataFrame(data, index = [True, False, True]) ...

Read More
Showing 411–418 of 418 articles
« Prev 1 38 39 40 41 42 Next »
Advertisements