0

I want to read the below CSV file into read_csv, due to the special characters in the CSV file , cant read the file properly, missing special characters in the column names in the data frame , and data is going here and there, but excel data is showing properly. can you help to fix this issue, want to skip 5 rows and read the remaining data as it is and rename the column name

CSV file:- $$PROGRAM$$ transistor.csv
$$DEVICE$$ 1
$$LOT$$ lot
$$DATE$$ 7/28/2021

$$FORMAT$$ ,SERIAL,COND=Temp,COND=vdd
1,BA1,25,1.2,7/12/201
1,BA2,25,1.2
1,BA2,25,1.2
1,BA3,25,1.2

import pandas as pd
import numpy as np
x=pd.read_csv(r"\trial.csv",index_col=None, header=0, skiprows=5, error_bad_lines=False,low_memory=False,encoding='utf8')

OUTPUT:-X

𝐹𝑂𝑅𝑀𝐴𝑇 SERIAL COND=Temp COND=vdd-
1 BA1 25 1.2 7/12/201-
1 BA2 25 1.2 NaN-
1 BA2 25 1.2 NaN-
1 BA3 25 1.2 NaN-

Expected output:
enter image description here

what iam getting:-
enter image description here

2
  • What would you expect? It seems fine to me, you have 4 columns, the last one has 4 missing values. Using index_col=0 is not going to prevent the first value to be used as index, but you can do x=x.reset_index(). Please provide the expected output for more help Commented Jul 28, 2021 at 11:14
  • @mozway Thank you for response , please refer to question for expected output Commented Jul 28, 2021 at 12:23

1 Answer 1

1

I think the problem is that your first row of data actually contains 5 values while your header only has 4 column names (the name for the date column is missing).

You can try to skip the header and provide column labels:

pd.read_csv(r"\trial.csv",
    skiprows=6,
    names=['FORMAT', 'SERIAL', 'COND=TEMP', 'COND=vdd', 'date'],
    error_bad_lines=False,
    low_memory=False,
    encoding='utf8')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.