How to add a list as a new column to an existing DataFrame in Python?
The simplest way to append a list as a new column to a Pandas DataFrame in Python is to use the syntaxe df[columnName]=list
. Let's consider the following dataframe:
>>> import pandas as pd
>>> df = pd.DataFrame([[1, 2], [4, 5]], columns = ["col1", "col2"])
col1 col2
0 1 2
1 4 5
The following command appends a list to the DataFrame as a new column named col3
:>>> df['col3'] = [3, 6]
col1 col2 col3
0 1 2 3
1 4 5 6
>>> df['col3'] = [3, 4]
col1 col2 col3
0 1 2 3
1 4 5 4
The simplest way to append a list as a new column to a Pandas DataFrame in Python is to use the syntaxe df[columnName]=list
. Let's consider the following dataframe:
>>> import pandas as pd
>>> df = pd.DataFrame([[1, 2], [4, 5]], columns = ["col1", "col2"])
col1 col2
0 1 2
1 4 5
The following command appends a list to the DataFrame as a new column named col3
:>>> df['col3'] = [3, 6]
col1 col2 col3
0 1 2 3
1 4 5 6
>>> df['col3'] = [3, 4]
col1 col2 col3
0 1 2 3
1 4 5 4
The simplest way to append a list as a column to a Pandas DataFrame in Python is to use the syntaxe df[columnName]=list
. Let's consider the following dataframe:
>>> import pandas as pd
>>> df = pd.DataFrame([[1, 2], [4, 5]], columns = ["col1", "col2"])
col1 col2
0 1 2
1 4 5
The following command appends a list to the DataFrame as a new column named col3
:
>>> df['col3'] = [3, 4]
col1 col2 col3
0 1 2 3
1 4 5 4
# | ID | Query | URL | Count |
---|