Ask Your Question
1

How can we choose or change a particular array within a Pandas DataFrame?

asked 2023-06-29 01:01:43 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-29 01:30:02 +0000

pufferfish gravatar image

We can choose or change a particular array within a Pandas DataFrame by using the column labels.

To select a particular array, we can use the square bracket notation and pass the label of the column we want to select as an argument. For example, to select the 'name' column from a DataFrame called 'df', we can use the following code:

name_array = df['name']

To change the values in a particular array, we can also use the square bracket notation and assign new values to the array. For example, to change the values in the 'name' column of the 'df' DataFrame, we can use the following code:

df['name'] = ['Alice', 'Bob', 'Charlie', 'David']

This will replace the current values in the 'name' column with the new values specified in the list.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-29 01:01:43 +0000

Seen: 12 times

Last updated: Jun 29 '23