“Pandy dołącz nową kolumnę” Kod odpowiedzi

Jak dodać kolumnę do pandas DF

#using the insert function:
df.insert(location, column_name, list_of_values) 
#example
df.insert(0, 'new_column', ['a','b','c'])
#explanation:
#put "new_column" as first column of the dataframe
#and puts 'a','b' and 'c' as values

#using array-like access:
df['new_column_name'] = value

#df stands for dataframe
Annoyed Antelope

Pandy dołącz nową kolumnę

# Append a new column as last
df["newColumnName"] = values
Av3

Dodaj nową kolumnę do PandaS DataFrame

# Import pandas package
import pandas as pd
 
# Define a dictionary containing Students data
data = {'Name': ['Jai', 'Princi', 'Gaurav', 'Anuj'],
        'Height': [5.1, 6.2, 5.1, 5.2],
        'Qualification': ['Msc', 'MA', 'Msc', 'Msc']}
 
# Convert the dictionary into DataFrame
df = pd.DataFrame(data)
 
# Declare a list that is to be converted into a column
address = ['Delhi', 'Bangalore', 'Chennai', 'Patna']
 
# Using 'Address' as the column name
# and equating it to the list
df['Address'] = address
 
# Observe the result
df
Sibahle Molphy

Odpowiedzi podobne do “Pandy dołącz nową kolumnę”

Pytania podobne do “Pandy dołącz nową kolumnę”

Więcej pokrewnych odpowiedzi na “Pandy dołącz nową kolumnę” w Python

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu