Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exclude first row when importing data from excel into Python

I have a partial code to import excel into Python as strings. How I can exclude first row when importing data from excel into Python?

import pandas as pd
data = pd.read_excel(".xlsx", parse_cols="A,C,E,G, I, K, M, O, Q, S, U, W, Y, AA, AC, AE, AG, AI, AK, AM, AO, AQ, AS, AU, AW, AY, BA, BC, BE, BG, BI, BK, BM, BO, BQ, BS, BU, BW, BY, CA, CC, CE, CG, CI, CK, CM, CO, CQ, CS, CU, CW, CY, DA, DC, DE, DG, DI, DK, DM, DO, DQ, DS, DU, DW, DY, EA, EC, DE, EG, EI, EK, EM, EO, EQ, ES, EU, EW, EY")
data = data.to_string()
like image 435
Ajml Avatar asked Aug 26 '17 06:08

Ajml


People also ask

How do I skip the first row in Excel using Python?

Method 1: Skip One Specific Row #import DataFrame and skip 2nd row df = pd. Method 2: Skip Several Specific Rows #import DataFrame and skip 2nd and 4th row df = pd. Method 3: Skip First N Rows #import DataFrame and skip first 2 rows df = pd.

How do I get Excel to exclude the first 5 rows?

Select the header or the first row of your list and press Shift + Ctrl + ↓(the drop down button), then the list has been selected except the first row.

How do I skip the first column in Excel in Python?

Skip Columns From Excel Sheet Sometimes while reading an excel sheet into pandas DataFrame you may need to skip columns, you can do this by using usecols param. This takes values {int, str, list-like, or callable default None}. To specify the list of column names or positions use a list of strings or a list of int.


1 Answers

The pandas documentation for the pd.read_excel method mentions a skiprows parameter that you can use to exclude the first row of your excel file.

Example

import pandas as pd
data = pd.read_excel("file.xlsx", parse_cols="A,C,E,G", skiprows=[0])

Source: pandas docs

like image 117
Onel Harrison Avatar answered Sep 30 '22 09:09

Onel Harrison