파이썬은 데이터 프레임에 열을 추가합니다

코드 예제

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
16
0

데이터 프레임 팬더에 행 추가

df = df.append({'a':1, 'b':2}, ignore_index=True)
3
0

팬더 df 에 새 열을 추가하는 방법

import pandas as pd

data = {'Name': ['Josh', 'Stephen', 'Drake', 'Daniel'], 
        'Height': [5.5, 6.0, 5.3, 4.9]}

'''
printing data at this point will show the following
      Name  Height
0     Josh     5.1
1  Stephen     6.2
2    Drake     5.1
3   Daniel     5.2
'''

df.insert(2, "Age", [20, 21, 20, 19])

'''
printing data now will show the following

      Name  Height  Age
0     Josh     5.1   20
1  Stephen     6.2   21
2    Drake     5.1   20
3   Daniel     5.2   19
'''

1
0

파이썬 데이터 프레임 팬더에 푸시

df = pd.DataFrame({
    'a':[1,2,3],
    'b':[5,6,7]
})

df2 = pd.DataFrame({
    'a':[11,12,13],
    'b':[15,16,17]
})

df = df.append(df2, ignore_index = True )

print(df)
0
0

하나의 열 팬더 데이터 프레임 추가

df1 = df1.join(df2[column])

비슷한 페이지

예제가있는 유사한 페이지

다른 언어로

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

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