By iNoob


2018-04-16 13:01:55 8 Comments

I have the following error builtins.AssertionError: 12 columns passed, passed data had 6 columns The last 6 Columns datawise will vary so Im happy to have None in the areas the data is missing. However I cant seem to find a simple way to do this, im pretty sure there must be an option for it but I cant see it in the docs or any google searches.

Any help would be apprecaited. I would like to reiterate that I know what is causing the problem and I know data is missing from coloumns. I would like to ignore missing data and am ahppy to have None or NaN in the output csv.

1 comments

@zipa 2018-04-16 13:24:46

I imagine you have fixed headers, so my solution would be to extend each row respectively:

import pandas as pd
import numpy as np

columns = ('Person', 'Title', 'AnotherPerson', 'AnotherPerson2', 'AnotherPerson3', 'AnotherPerson4', 'Date', 'Group')
mandatory = len(columns)

data = [[1,2,3], [1, 2], [1, 2, 3, 4]]
data = list(map(lambda x: dict(enumerate(x)), data))

data = [[item.get(i, np.nan) for i in range(mandatory)] for item in data]

df = pd.DataFrame(data=data, columns=columns)

Related Questions

Sponsored Content

13 Answered Questions

[SOLVED] Select rows from a DataFrame based on values in a column in pandas

9 Answered Questions

[SOLVED] Parsing values from a JSON file?

  • 2010-05-14 15:54:20
  • michele
  • 2266083 View
  • 1254 Score
  • 9 Answer
  • Tags:   python json parsing

21 Answered Questions

[SOLVED] Is there a simple way to delete a list element by value?

  • 2010-05-08 07:48:28
  • zjm1126
  • 1341771 View
  • 755 Score
  • 21 Answer
  • Tags:   python list

21 Answered Questions

[SOLVED] Peak detection in a 2D array

11 Answered Questions

[SOLVED] How to drop rows of Pandas DataFrame whose value in certain columns is NaN

2 Answered Questions

[SOLVED] Pearson correlation and nan values

10 Answered Questions

3 Answered Questions

1 Answered Questions

[SOLVED] Fill NaNs in dataframe column depending on last value

  • 2017-03-17 17:00:18
  • Captain Whippet
  • 93 View
  • 2 Score
  • 1 Answer
  • Tags:   python pandas numpy

Sponsored Content