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.


@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

21 Answered Questions

[SOLVED] Peak detection in a 2D array

18 Answered Questions

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

  • 2010-05-08 07:48:28
  • zjm1126
  • 1053156 View
  • 608 Score
  • 18 Answer
  • Tags:   python list

7 Answered Questions

[SOLVED] Parsing values from a JSON file?

  • 2010-05-14 15:54:20
  • michele
  • 1792745 View
  • 1003 Score
  • 7 Answer
  • Tags:   python json parsing

10 Answered Questions

2 Answered Questions

[SOLVED] Pearson correlation and nan values

11 Answered Questions

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

9 Answered Questions

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

3 Answered Questions

[SOLVED] How to count number of rows in a group in pandas group by object?

1 Answered Questions

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

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

Sponsored Content