0

i prepared a dict with some vals filled and the rest empty (i need to merge it with other df later so those empty ones are required)

data = {'name':['a', 'b', 'c'],
       'geojson':['val1', 'val2' 'val3'],
       'lat lng:':[],
       'place_id':[],
       'type':[],
       'hierarchia':[1, 1, 1]}

now i want to make a df from this dict, but it raises an error

import pandas as pd
cols = list(data.keys())
df = pd.DataFrame(data, columns = cols)
df
ValueError: arrays must all be same length

i understand that they all need the same number of values, but is it possible to just fill this up somehow with NaN's during df creation?

i tried addind an argument fillna=True at the end but it's not a thing, sadly

adamDud
  • 309
  • 1
  • 3
  • 10
  • you can try this `pd.DataFrame(data.values(), index=data.keys()).T` – Naga kiran Aug 09 '21 at 15:07
  • @sushanth i've seen this but it's just filling the empty cols with "placeholders", and i actually need some columns to be empty. I could do that but i'm wondering is there a built in method for NaN filling during creation that i don't know of – adamDud Aug 09 '21 at 15:09

0 Answers0