Python | Pandas Working With Text Data - GeeksforGeeks
# importing pandas module
import pandas as pd
# Define a dictionary containing employee data
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
'Age':[27, 24, 22, 32],
'Address':['Nagpur', 'Kanpur', 'Allahabad', 'Knnuaj'],
'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
# Convert the dictionary into DataFrame
df = pd.DataFrame(data)
# dropping null value columns to avoid errors
df.dropna(inplace = True)
# new data frame with split value columns
df["Address"]= df["Address"].str.split("a", n = 1, expand = True)
# df display
print(df)
--> 에러발생
[pandas] ValueError: Columns must be same length as key
해결 인덱스 추가
# importing pandas module
import pandas as pd
# Define a dictionary containing employee data
data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
'Age':[27, 24, 22, 32],
'Address':['Nagpur', 'Kanpur', 'Allahabad', 'Knnuaj'],
'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
# Convert the dictionary into DataFrame
df = pd.DataFrame(data)
# dropping null value columns to avoid errors
df.dropna(inplace = True)
# new data frame with split value columns
print(df)
print("\n")
df["Address"]= df["Address"].str.split("a", n = 1, expand = True)[0]
# df display
print(df)
[pandas] ValueError: Columns must be same length as key : learnpython (reddit.com)
'python' 카테고리의 다른 글
| ellipsis ( ... 의미 in python , numpy) (0) | 2023.01.14 |
|---|---|
| dict 활용해서 학생들 점수와 학점 저장하기. (0) | 2022.07.10 |