- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 507 Articles for Pandas
![Prasad Naik](https://www.tutorialspoint.com/assets/profiles/318467/profile/60_239124-1617874456.jpg)
306 Views
In this program, we will replace or, in other words, reset the default index in the Pandas dataframe. We will first make a dataframe and see the default index and then replace this default index with our custom index.AlgorithmStep 1: Define your dataframe. Step 2: Define your own index. Step 3: Replace the default index with your index using the reset function in Pandas library.Example Codeimport pandas as pd dataframe = {'Name':["Allen", "Jack", "Mark", "Vishal"], 'Marks':[85, 92, 99, 87]} df = pd.DataFrame(dataframe) print("Before using reset_index:", df) own_index = ['a', 'j', 'm', 'v'] df = pd.DataFrame(dataframe, own_index) ... Read More
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
480 Views
Write a Python code to find price column value between 30000 to 70000 and print the id and product columns of the last three rows from the products.csv file. Result for price column value between 30000 to 70000 and id and product columns last three rows are − id product 79 80 Truck 81 82 Bike 98 99 TruckSolution 1 Read data from products.csv file and assign to dfdf = pd.read_csv('products.csv ')Apply pandas slicing to access all rows of price column between 30000 to 50000 as, df[df.iloc[:, 4].between(30000, 50000)Save the above result to df1Apply slicing to access last ... Read More
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
740 Views
Write a Python program to read data from the products.csv file and print the number of rows and columns. Then print the ‘product’ column value matches ‘Car’ for first ten rowsAssume, you have ‘products.csv’ file and the result for number of rows and columns and ‘product’ column value matches ‘Car’ for first ten rows are −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 1530 ... Read More
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
748 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
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
670 Views
The result for splitting camel case strings into series as, enter the sring: pandasSeriesDataFrame Series is: 0 pandas 1 Series 2 Data 3 Frame dtype: objectTo solve this, we will follow the steps given below −SolutionDefine a function that accepts the input stringSet result variable with the condition as input is not lowercase and uppercase and no ’_’ in input string. It is defined below, result = (s != s.lower() and s != s.upper() and "_" not in s)Set if condition to check if the result is true the apply re.findall method to find camel case ... Read More
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
148 Views
Assume, you have two series and the result for combining two series into dataframe as, Id Age 0 1 12 1 2 13 2 3 12 3 4 14 4 5 15To solve this, we can have three different approaches.Solution 1Define two series as series1 and series2Assign first series into dataframe. Store it as dfdf = pd.DataFrame(series1)Create a column df[‘Age’] in dataframe and assign second series inside to df.df['Age'] = pd.DataFrame(series2)ExampleLet’s check the following code to get a better understanding −import pandas as pd series1 = pd.Series([1, 2, 3, 4, 5], name='Id') series2 = pd.Series([12, 13, 12, 14, 15], name='Age') ... Read More
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
11K+ Views
Assume, you have a dataframe and the result for a date, month, year column is, date day month year 0 17/05/2002 17 05 2002 1 16/02/1990 16 02 1990 2 25/09/1980 25 09 1980 3 11/05/2000 11 05 2000 4 17/09/1986 17 09 1986To solve this, we will follow the steps given below −SolutionCreate a list of dates and assign into dataframe.Apply str.split function inside ‘/’ delimiter to df[‘date’] column. Assign the result to df[[“day”, “month”, “year”]].ExampleLet’s check the following code to get a better understanding −import ... Read More
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
131 Views
Assume, you have a series and the result for converting to dummy variable as, Female Male 0 0 1 1 1 0 2 0 1 3 1 0 4 0 1 5 0 0 6 1 0 7 1 0To solve this, we will follow the steps given below −SolutionCreate a list with ‘Male’ and ‘Female’ elements and assign into Series.Apply get_dummies function inside series and set dummy_na value as False. It is defined below, pd.get_dummies(series, dummy_na=False)ExampleLet’s check the following code to get ... Read More
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
130 Views
Assume, you have a dataframe and the result for converted to latex as, \begin{tabular}{lrr} \toprule {} & Id & Age \ \midrule 0 & 1 & 12 \ 1 & 2 & 13 \ 2 & 3 & 14 \ 3 & 4 & 15 \ 4 & 5 & 16 \ \bottomrule \end{tabular}SolutionTo solve this, we will follow the steps given below −Define a dataframeApply to_latex() function to the dataframe and set index and multirow values as True. It is defined below, df.to_latex(index = True, multirow = True)ExampleLet’s ... Read More
![Vani Nalliappan](https://www.tutorialspoint.com/assets/profiles/304793/profile/60_62256-1613462273.jpg)
281 Views
The result for generating even length random four-digit pin numbers as, enter the series size 4 Random four digit pin number series 0 0813 1 7218 2 6739 3 8390To solve this, we will follow the steps given below −SolutionCreate an empty and list and set result as TrueSet while loop and get the size from the userSet if condition to find the size is even or odd. If the size is odd then assign the result as False and runs the loop until an even number is entered.l = [] while(True): size = int(input("enter ... Read More