Found 33676 Articles for Programming

Python - Read csv file with Pandas without header?

AmitDiwan
Updated on 26-Aug-2023 08:31:46

38K+ Views

To read CSV file without header, use the header parameter and set it to “None” in the read_csv() method.Let’s say the following are the contents of our CSV file opened in Microsoft Excel −At first, import the required library −import pandas as pdLoad data from a CSV file into a Pandas DataFrame. This will display the headers as well −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")While loading, use the header parameter and set None to load the CSV without header −pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv", header=None)ExampleFollowing is the code −import pandas as pd # Load data from a CSV file into a Pandas DataFrame dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv") ... Read More

Python - Draw a Scatter Plot for a Pandas DataFrame

AmitDiwan
Updated on 30-Sep-2021 11:39:36

709 Views

Scatter Plot is a data visualization technique. Use the plot.scatter() to plot the Scatter Plot. At first, Let us import the required libraries −We have our data with Team Records. Set it in the Pandas DataFrame −data = [["Australia", 2500], ["Bangladesh", 1000], ["England", 2000], ["India", 3000], ["Srilanka", 1500]] dataFrame = pd.DataFrame(data, columns=["Team", "Rank_Points"]) Let us plot now with the columns −dataFrame.plot.scatter(x="Team", y="Rank_Points")ExampleFollowing is the code −import pandas as pd import matplotlib.pyplot as mp # our data data = [["Australia", 2500], ["Bangladesh", 1000], ["England", 2000], ["India", 3000], ["Srilanka", 1500]] # dataframe dataFrame = pd.DataFrame(data, columns=["Team", "Rank_Points"]) ... Read More

Rename column name with an index number of the CSV file in Pandas

AmitDiwan
Updated on 30-Sep-2021 11:36:14

2K+ Views

Using columns.values(), we can easily rename column name with index number of a CSV file.Let’s say the following are the contents of our CSV file opened in Microsoft Excel −We will rename the column names. At first, load data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")Display all the column names from the CSV −dataFrame.columnsNow, rename column names −dataFrame.columns.values[0] = "Car Names" dataFrame.columns.values[1] = "Registration Cost" dataFrame.columns.values[2] = "Units Sold"ExampleFollowing is the code −import pandas as pd # Load data from a CSV file into a Pandas DataFrame: dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv") print("Reading the CSV file...", dataFrame) ... Read More

Select rows that contain specific text using Pandas

AmitDiwan
Updated on 30-Sep-2021 11:29:38

827 Views

To select rows that contain specific text, use the contains() method. Let’s say the following is our CSV file path −C:\Users\amit_\Desktop\SalesRecords.csvAt first, let us read the CSV file and create Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")Now, let us select rows that contain specific text “BMW” −dataFrame = dataFrame[dataFrame['Car'].str.contains('BMW')]ExampleFollowing is the code −import pandas as pd # reading csv file dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv") print("DataFrame...", dataFrame) # select rows containing text "BMW" dataFrame = dataFrame[dataFrame['Car'].str.contains('BMW')] print("Fetching rows with text BMW ...", dataFrame)OutputThis will produce the following output −DataFrame ...            Car       Place   UnitsSold ... Read More

Node.js – process.connected Property

Mayank Agarwal
Updated on 29-Oct-2021 07:24:49

117 Views

The process.connected property returns True if an IPC channel is connected and will return False after the process.disconnect() method is called. This happens only when the node process is spawned with an IPC channel (i.e., Child process and Cluster).Once the process.connected property is false, no messages can be sent over the IPC channel.Syntaxprocess.connectedExample 1Create two files "parent.js" and "child.js" as follows −parent.js// process.connected Property Demo Example // Importing the child_process modules const fork = require('child_process').fork; // Attaching the child process file const child_file = 'util.js'; // Spawning/calling child process const child = fork(child_file);child.jsconsole.log('In Child') // Check ... Read More

Node.js – Timers Module – Scheduling Timers

Mayank Agarwal
Updated on 27-Oct-2021 07:51:47

656 Views

The timers module contains functions that can execute code after a certain period of time. You do not need to import the timer module explicitly, as it is already globally available across the emulated browser JavaScript API.Timers module is mainly categorised into two categoriesScheduling Timers − This timer schedules the task to take place after a certain instant of time.setImmediate()setInterval()setTimeout()Cancelling Timers − This type of timers cancels the scheduled tasks which is set to take place.   ClearImmediate()clearInterval()clearTimeout()Scheduling Timers1. setTimeout() MethodThe setTimeout() method schedules the code execution after a designated number of milliseconds. Only after the timeout has occurred, the code ... Read More

Python Pandas – Merge DataFrame with many-to-one relation

AmitDiwan
Updated on 29-Sep-2021 11:50:28

2K+ Views

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

Python - Select multiple columns from a Pandas dataframe

AmitDiwan
Updated on 29-Sep-2021 11:41:31

3K+ Views

Let’s say the following are the contents of our CSV file opened in Microsoft Excel −At first, load data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")To select multiple column records, use the square brackets. Mention the columns in the brackets and fetch multiple columns from the entire dataset −dataFrame[['Reg_Price', 'Units']] ExampleFollowing is the code −import pandas as pd # Load data from a CSV file into a Pandas DataFrame: dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv") print("Reading the CSV file...", dataFrame) # displaying two columns res = dataFrame[['Reg_Price', 'Units']]; print("Displaying two columns : ", res)OutputThis will produce the ... Read More

Python Pandas - Select a subset of rows from a dataframe

AmitDiwan
Updated on 29-Sep-2021 11:35:56

1K+ Views

To select a subset of rows, use conditions and fetch data.Let’s say the following are the contents of our CSV file opened in Microsoft Excel −At first, load data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")Let’s say we want the Car records with “Units” more than 100 i.e. subset of rows. For this, use −dataFrame[dataFrame["Units"] > 100] Now, let’s say we want the Car records with “Reg_Price” less than 100 i.e. subset of rows. For this, use −dataFrame[dataFrame["Reg_Price"] < 3000]ExampleFollowing is the code − import pandas as pd # Load data from a CSV file ... Read More

Python - How to select a subset of a Pandas DataFrame

AmitDiwan
Updated on 29-Sep-2021 11:23:19

383 Views

Let’s say the following are the contents of our CSV file opened in Microsoft Excel −At first, load data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")To select a subset, use the square brackets. Mention the column in the brackets and fetch single column from the entire dataset −dataFrame['Car'] ExampleFollowing is the code − import pandas as pd # Load data from a CSV file into a Pandas DataFrame dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv") print("Reading the CSV file...", dataFrame) # displaying only a single column res1 = dataFrame['Car']; # displaying only a subset print("Displaying only one column ... Read More

Advertisements