Home > Mobile >  How to read csv file as dataframe with missing headers and data shift problem in certain rows due to
How to read csv file as dataframe with missing headers and data shift problem in certain rows due to

Time:04-04

I want to read this CSV file in data frame

Username,Identifier,First name,Last name,Department,Location

There is data shift in first and second row due to extra comma.

I want to read the daa as it is with missing headers.

There is data shift in first and second row due to extra comma. Now when I read it with

df = pd.read_csv('Commission.csv', index_col=False) 

It throws warning ParserWarning: Length of header or names does not match length of data. This leads to a loss of data with index_col=False.

and gives output

So how can I get data as:

Username Identifier First name Last Name Department Location Somename Somename
booker12 9012 Rachel Booker Sales Manchester
grey07 2070 Laura Grey Depot London
johnson81 4081 Craig Johnson Depot London
jenkins46 9346 Mary Jenkins Engineering Manchester
smith79 5079 Jamie Smith Engineering Manchester

CodePudding user response:

you have to use pd.merge with NaN with the right column

CodePudding user response:

Try DataFrame.dropna()

df.dropna()
  • Related