데이터 프레임 팬더에 다른 열 추가

코드 예제

27
0

팬더 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
6
0

파이썬 팬더 데이터 프레임에 열을 추가하는 방법

# Basic syntax:
pandas_dataframe['new_column_name'] = ['list', 'of', 'column', 'values']

# Note, the list of column values must have length equal to the number
# 	of rows in the pandas dataframe you are adding it to.

# Add column in which all rows will be value:
pandas_dataframe['new_column_name'] = value
# Where value can be a string, an int, a float, and etc 
0
0

다른 df 에서 df 에 열 추가

# pre 0.24
feature_file_df['RESULT'] = RESULT_df['RESULT'].values
# >= 0.24
feature_file_df['RESULT'] = RESULT_df['RESULT'].to_numpy()
0
0

데이터 프레임에 새 열을 추가하는 방법

# 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 

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................