To iterate and fetch the rows containing the desired text, use the itertuples() and find() method. The itertuples() iterate over DataFrame rows.At first, let us import the required library with an alias −import pandas as pdOur CSV is on the Desktop as shown in the below path −C:\Users\amit_\Desktop\CarRecords.csv Let us read the CSV file and create Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\CarRecords.csv")Iterate and fetch the rows containing a specific text. We are fetching Car column with text “Lamborghini” −for k in dataFrame.itertuples(): if k[1].find('Lamborghini') != -1: print(k)ExampleFollowing is the code import pandas as pd ... Read More
To merge all excel files in a folder, use the Glob module and the append() method.Let’s say the following are our excel files on the Desktop −Sales1.xlsxSales2.xlsxNote − You may need to install openpyxl and xlrd packages.At first, set the path where all the excel files you want to merge are located. Get the excel files and read them using glob −path = "C:\Users\amit_\Desktop\" filenames = glob.glob(path + "\*.xlsx") print('File names:', filenames)Next, create an empty dataframe for the merged output excel file that will get the data from the above two excel files −outputxlsx = pd.DataFrame()Now, the actual process ... Read More
To sort CSV by a single column, use the sort_values() method. Set the column using which you want to sort in the sort_values() method.At first, let’s read our CSV file “SalesRecords.csv”with DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesRecords.csv")Sort according to a single column “Car” −dataFrame.sort_values("Car", axis=0, ascending=True, inplace=True, na_position='first')Next, sort according to a single column “Reg_Price” −dataFrame.sort_values("Reg_Price", axis=0, ascending=True, inplace=True, na_position='first')ExampleFollowing is the codeimport pandas as pd # DataFrame to read our input CS file dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesRecords.csv") print("Input CSV file = ", dataFrame) # sorting according to Car column dataFrame.sort_values("Car", axis=0, ascending=True, inplace=True, na_position='first') print("Sorted CSV file (according to ... Read More
To read all excel files in a folder, use the Glob module and the read_csv() method. Let’s say the following are our excel files in a directory −At first, let us set the path and get the csv files. Our CSV files are in the folder MyProject −path = "C:\Users\amit_\Desktop\MyProject\"Read files with extension .csv from the above path −filenames = glob.glob(path + "\*.csv") Let us now write a for loop to iterate all csv files, read and print them −for file in filenames: # reading csv files print("Reading file = ", file) ... Read More
Swarm Plot in Seaborn is used to draw a categorical scatterplot with non-overlapping points. The seaborn.swarmplot() is used for this. Draw swarms of observations on top of a box plot using the seaborn.boxplot().Let’s say the following is our dataset in the form of a CSV file −Cricketers2.csvAt first, import the required libraries −import seaborn as sb import pandas as pd import numpy as np import matplotlib.pyplot as pltLoad data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers2.csv") Draw swarms of observations on top of a box plot −sb.boxplot(x = "Matches", y = "Role", data= dataFrame, whis=np.inf) sb.swarmplot(x ... Read More
Swarm Plot in Seaborn is used to draw a categorical scatterplot with non-overlapping points. The seaborn.swarmplot() is used for this. Control swarm order by passing an explicit order i.e. ordering on the basis of a specific column using the order parameter −Let’s say the following is our dataset in the form of a CSV file −Cricketers2.csvAt first, import the required libraries −import seaborn as sb import pandas as pd import matplotlib.pyplot as pltLoad data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers2.csv") Plotting swarm plot with Academy and Matches. Control swarm order by passing an explicit order ... Read More
Swarm Plot in Seaborn is used to draw a categorical scatterplot with non-overlapping points. The seaborn.swarmplot() is used for this. To group the swarms by two categorical variables, set those variables in the swarmplot() using the x, y or hue parameters.Let’s say the following is our dataset in the form of a CSV file: Cricketers2.csvAt first, import the required libraries −import seaborn as sb import pandas as pd import matplotlib.pyplot as pltLoad data from a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers2.csv") Group the swarms by two categorical variables −sb.swarmplot(x = "Role", y = "Matches", hue = "Academy", ... Read More
Violin Plot in Seaborn is used to draw a combination of boxplot and kernel density estimate. The seaborn.violinplot() is used for this. Set explicit order using the order parameter of the violinplot().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 a CSV file into a Pandas DataFrame −dataFrame = pd.read_csv("C:\Users\amit_\Desktop\Cricketers.csv") Plotting violin plot with Role and Age. Control order by passing an explicit order i.e. ordering on the basis of "Role".sb.violinplot(x = 'Role', y ... Read More
To read all excel files in a directory, use the Glob module and the read_excel() method.Let’s say the following are our excel files in a directory −Sales1.xlsxSales2.xlsxAt first, set the path where all the excel files are located. Get the excel files and read them using glob −path = "C:\Users\amit_\Desktop\" filenames = glob.glob(path + "\*.xlsx") print('File names:', filenames)Next, use the for loop to iterate and read all the excels files in a specific directory. We are also using read_excel() −for file in filenames: print("Reading file = ", file) print(pd.read_excel(file))ExampleFollowing is the complete code ... Read More
To merge more than one CSV files into a single Pandas dataframe, use read_csv. At first, import the required Pandas library. Here. We have set pd as an alias −import pandas as pdNow, let’s say the following are our CSV Files −Sales1.csvSales2.csvWe have set the path as string. Both the files are on the Desktop −file1 = "C:\Users\amit_\Desktop\sales1.csv" file2 = "C:\Users\amit_\Desktop\sales2.csv"Next, merge the above two CSV files. The pd.concat() merge the CSV files together −dataFrame = pd.concat( map(pd.read_csv, [file1, file2]), ignore_index=True)ExampleFollowing is the code −import pandas as pd file1 = "C:\Users\amit_\Desktop\sales1.csv" file2 = "C:\Users\amit_\Desktop\sales2.csv" print("Merging ... Read More
 Data Structure
 Networking
 RDBMS
 Operating System
 Java
 iOS
 HTML
 CSS
 Android
 Python
 C Programming
 C++
 C#
 MongoDB
 MySQL
 Javascript
 PHP