I want to create a dataframe with one of the column as a list or array But an attempt to do so gives an error 'Must have equal len keys and value when setting with an iterable' Please support
eg data.loc[0,'emails']={'[email protected]','[email protected]'} =>error
data.loc[0,'emails']='[email protected]' =>No error
Data=>
> Name | emails
___________________________
> Judas |['[email protected]','[email protected]']
> Priest|['[email protected]','[email protected]','[email protected]']
This scenario could be one like trying to get only list of emails as a column from one of the columns which contains very long texts.
After you assign a list
like or array
like value to the columns, the column should be considered as type object
df=pd.DataFrame({'Name':['Juda','Pri']})
df['Email']=''
df.Email=df.Email.astype(object)
df.loc[0,'Email']={'[email protected]','[email protected]'}
df
Out[511]:
Name Email
0 Juda {[email protected], [email protected]}
1 Pri
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加