How to create a pandas dataframe with a column as array

Thunder

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.

BEN_YO

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]

編集
0

コメントを追加

0

関連記事

分類Dev

How to speed up Pandas apply function to create a new column in the dataframe?

分類Dev

How to create new values in a pandas dataframe column based on values from another column

分類Dev

HoloViews: create boxplots for every column in a pandas dataframe

分類Dev

How to create new column conditional on existing columns in pandas dataframe using for loop

分類Dev

How to create a pandas dataframe column using a list of numpy nd-arrays?

分類Dev

Check if values of a column is in another column array in a pandas dataframe

分類Dev

How to drop Pandas dataframe columns based on another boolean array's column values?

分類Dev

How to sort a Dataframe by the ocurrences in a column in Python (pandas)

分類Dev

how to assign hierarchical column names in pandas dataframe

分類Dev

How to create a Pandas DataFrame from a list of OrderedDicts?

分類Dev

create new column in a dataframe using custom aggregate function in pandas

分類Dev

How to create pandas matrix from one column

分類Dev

How to append an element to an array column of a Spark Dataframe?

分類Dev

How to append an element to an array column of a Spark Dataframe?

分類Dev

python - how to append numpy array to a pandas dataframe

分類Dev

how to check in pandas if element is in column which is an array

分類Dev

Create a peak column in dataframe

分類Dev

Create a date column for dataframe

分類Dev

Thresholding a pandas dataframe by column

分類Dev

Pandas dataframe rename column

分類Dev

Binarizing column in Pandas dataframe

分類Dev

How to get percentage from how filled a pandas dataframe column is?

分類Dev

How to group by column in a dataframe and create pivot tables in a loop

分類Dev

How do I flatten a hierarchical column index in a pandas DataFrame?

分類Dev

How to decile python pandas dataframe by column value, and then sum each decile?

分類Dev

How to loop over all but last column in pandas dataframe + indexing?

分類Dev

How to extract city,state from a column in pandas dataframe?

分類Dev

How to replace certain rows by shared column values in pandas DataFrame?

分類Dev

Pandas - How to repeat dataframe n times each time adding a column

Related 関連記事

  1. 1

    How to speed up Pandas apply function to create a new column in the dataframe?

  2. 2

    How to create new values in a pandas dataframe column based on values from another column

  3. 3

    HoloViews: create boxplots for every column in a pandas dataframe

  4. 4

    How to create new column conditional on existing columns in pandas dataframe using for loop

  5. 5

    How to create a pandas dataframe column using a list of numpy nd-arrays?

  6. 6

    Check if values of a column is in another column array in a pandas dataframe

  7. 7

    How to drop Pandas dataframe columns based on another boolean array's column values?

  8. 8

    How to sort a Dataframe by the ocurrences in a column in Python (pandas)

  9. 9

    how to assign hierarchical column names in pandas dataframe

  10. 10

    How to create a Pandas DataFrame from a list of OrderedDicts?

  11. 11

    create new column in a dataframe using custom aggregate function in pandas

  12. 12

    How to create pandas matrix from one column

  13. 13

    How to append an element to an array column of a Spark Dataframe?

  14. 14

    How to append an element to an array column of a Spark Dataframe?

  15. 15

    python - how to append numpy array to a pandas dataframe

  16. 16

    how to check in pandas if element is in column which is an array

  17. 17

    Create a peak column in dataframe

  18. 18

    Create a date column for dataframe

  19. 19

    Thresholding a pandas dataframe by column

  20. 20

    Pandas dataframe rename column

  21. 21

    Binarizing column in Pandas dataframe

  22. 22

    How to get percentage from how filled a pandas dataframe column is?

  23. 23

    How to group by column in a dataframe and create pivot tables in a loop

  24. 24

    How do I flatten a hierarchical column index in a pandas DataFrame?

  25. 25

    How to decile python pandas dataframe by column value, and then sum each decile?

  26. 26

    How to loop over all but last column in pandas dataframe + indexing?

  27. 27

    How to extract city,state from a column in pandas dataframe?

  28. 28

    How to replace certain rows by shared column values in pandas DataFrame?

  29. 29

    Pandas - How to repeat dataframe n times each time adding a column

ホットタグ

アーカイブ