- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write a Python program to read an Excel data from file and read all rows of first and last columns
Assume, you have an Excel file stored with the name of pandas.xlsx in your location.
To solve this, we will follow the steps given below −
Define pd.read_excel method to read data from pandas.xlsx file and save it as df
df = pd.read_excel('pandas.xlsx')
Apply df.iloc[:,0] to print all rows of first column
Apply df.iloc[:,-1] to print all rows of last column
Let’s see the below implementation to get a better understanding −
import pandas as pd df = pd.read_csv('products.csv') print("all rows of first column is") print(df.iloc[:,0]) print("all rows of last column is") print(df.iloc[:,-1])
all rows of first column is 0 1 1 2 2 3 3 4 4 5 ... 95 96 96 97 97 98 98 99 99 100 Name: id, Length: 100, dtype: int64 all rows of last column is 0 2019 1 2020 2 2018 3 2018 4 2018 ... 95 2019 96 2019 97 2018 98 2020 99 2018 Name: productionYear, Length: 100, dtype: int64
- Read and Write to an excel file using Python openpyxl module
- Write a program in Python to read CSV data from a file and print the total sum of last two rows
- Write a C program to read a data from file and display
- Write a program in Python to read sample data from an SQL Database
- How to create a file, write data into it and read data from it on iOS?
- Read last line from file in PHP
- Write a Python code to read JSON data from a file and convert it to dataframe, CSV files
- How to read/write data from/to .properties file in Java?
- How to open a file in read and write mode with Python?
- How to set read and write position in a file in Python?
- How to open a binary file in read and write mode with Python?
- Read Data from a Text File using C++
- How to read data from a file using FileInputStream?
- Read/Write Class Objects from/to File in C++