0
df = pd.read_csv('C:/Users/ymx19/Desktop/EHS/Location/results/Batch3_exclude_enterprise_wenran/first 100 - attribute/ABM.csv')
list_2 = ['a','b','c']
df.at[0, 'Attribute_consolidated'] = list_2

error code: ValueError: setting an array element with a sequence.

The goal is to add a list into pandas DataFrame cell. I did a similar thing before and it worked, but somehow the code is no longer working in this case.

Yumeng Xu
  • 179
  • 1
  • 2
  • 11
  • Use.`df.loc[0, 'Attribute_consolidated'] = list_2` – James Sep 03 '21 at 19:28
  • It shows another error: ValueError: Must have equal len keys and value when setting with an iterable – Yumeng Xu Sep 03 '21 at 19:31
  • Per [the top voted answer](https://stackoverflow.com/a/47548471/15497888) you are correct `at` is the method to use for this operation, but the second requirement is that the column must be of dtype `object` or you'll receive a "ValueError: setting an array element with a sequence" – Henry Ecker Sep 03 '21 at 19:32

0 Answers0