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
Programming Articles - Page 1040 of 3363
5K+ Views
To write pandas dataframe to a CSV file in Python, use the to_csv() method. At first, let us create a dictionary of lists −# 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'] }Now, create pandas dataframe from the above dictionary of lists −dataFrame = pd.DataFrame(d) Our output CSV file will generate on the Desktop since we have set the Desktop path below −dataFrame.to_csv("C:\Users\amit_\Desktop\sales1.csv\SalesRecords.csv")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', ... Read More
17K+ Views
To merge all CSV files, use the GLOB module. The os.path.join() method is used inside the concat() to merge the CSV files together. Some of the common methods we can use to merge multiple CSV Files into a single dataframe are as follows - os.path.join() and glob Merging CSV Files with glob Pattern ... Read More
697 Views
Suppose we have an array containing various integer values and a given length k. We have to find out the greatest subarray from the array of the given length. A subarray is said to be greater than another subarray, if subarray1[i] ≠ subarry2[i] and subarray1[i] > subarry2[i].So, if the input is like nums = [5, 3, 7, 9], k = 2, then the output will be [7, 9].To solve this, we will follow these steps −start := size of nums - kmax_element := nums[start]max_index := startwhile start >= 0, doif nums[start] > max_element is non-zero, thenmax_element := nums[start]max_index := startreturn ... Read More
280 Views
Violin Plot in Seaborn is used to draw a combination of boxplot and kernel density estimate. The seaborn.violinplot() is used for this. Plot a sinle violinplot usinga single column.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 single horizontal violin plot with Weight (kgs) column −sb.violinplot(dataFrame['Weight'])ExampleFollowing is the code −import seaborn as sb import pandas as pd import matplotlib.pyplot as plt # ... Read More
9K+ Views
In Python, to sort a CSV file by multiple columns, we can use the 'sort_values()' Method provided by the Python Pandas library. This method is used for sorting the values by taking column names as arguments. Some of the common methods for sorting a CSV file by multiple columns are as follows. sort_values() : To sort a DataFrame by multiple columns. sort_values() without inplace : To sort a DataFrame by ... Read More
350 Views
Count Plot in Seaborn is used to display the counts of observations in each categorical bin using bars. The seaborn.countplot() is used for this. Style the bars using the facecolor, linewidth and edgecolor parameters.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") Style and design the bars using the facecolor, linewidth and edgecolor parameters −sb.countplot(dataFrame["Age"], facecolor=(0, 0.0, 0, 0), linewidth=3, edgecolor=sb.color_palette("dark", 2))ExampleFollowing is the ... Read More
806 Views
Point Plot in Seaborn is used to show point estimates and confidence intervals using scatter plot glyphs. The seaborn.pointplot() is used for this. Set caps to the error bars using the capsize parameter.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") Setting caps to the error bars using the capsize parameter −sb.pointplot(dataFrame['Role'], dataFrame['Age'], capsize=.3)ExampleFollowing is the code −import seaborn as sb import pandas as ... Read More
852 Views
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. To control the order use the order parameter.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 box plot with Academy and Age. Control box order by passing an explicit order i.e. ordering on the basis of "Academy". Ordering using ... Read More
101 Views
Violin Plot in Seaborn is used to draw a combination of boxplot and kernel density estimate. The seaborn.violinplot() is used for this. Order with order parameter and set observations using inner parameter.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") Plot horizontal violin plot with Role and Age columns. Order with order parameter and set observations using inner parameter −sb.violinplot(x = 'Age', y = ... Read More
2K+ Views
Box Plot in Seaborn is used to draw a box plot to show distributions with respect to categories. To create a vertical Box Plot, use the seaborn.boxplot().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 a vertical box plot with Academy and Age −sb.boxplot( x = 'Academy', y = 'Age', data = dataFrame )ExampleFollowing is the complete code −import seaborn as sb import ... Read More