csv 파일 불러오기
{pandas dataframe 이름}.read_csv('{파일 이름.csv}')
ex) goemotion_train = pd.read_csv('data/goemotions_train_with_guid.csv')
tsv 파일 불러오기
{pandas dataframe 이름}.read_csv('{파일 이름.tsv}', sep="\t")
ex)goemotion_test = pd.read_csv('data/goemotions_test.tsv', sep="\t", header=None, names=['context','emotion', 'w'])
불필요한 열 지울때
{pandas dataframe 이름}.drop(labels = '{열 이름}', axis=1)
ex) goemotion_test = goemotion_test.drop(labels = 'Unnamed: 0', axis=1)
해당 값의 카운터를 알고 싶을때
{pandas dataframe 이름}.{보고싶은 열 값}..value_counts()
ex) out.emotion.value_counts()
데이터 프레임의 값을 카운트하고 싶을때
a = pd.DataFrame(prediction)
print(a.value_counts())
numpy.addrayy
=> .shape
list
import numpy as np
X = np.array([texts])
X.shape
데이터 전처리
데이터 타입들을 바꾸고 싶을 때
# 전체
data = data.astype('int')
# 부분만
PR_coding_df['pr'] = PR_coding_df['pr'].astype('string')
df 합치기
data = pd.concat([survey_positive, survey_negative, amazon_negative, amazon_positive])
Nan to zeor(Nan 값을 0으로 바꾸고 싶을 때)
df.fillna(0)
numpy array 데이터 타입 확인
arange로 numpy array 만들기
import numpy as np
arr = np.arange(10)
dtype으로 numpy array 데이터 타입 확인하기
arr.dtype
array to string
def listToString(s):
# initialize an empty string
str1 = " "
# return string
return (str1.join(s))
# Driver code
s = ['Geeks', 'for', 'Geeks']
print(listToString(s))
[ERROR]
encoding error
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x98 in position 595: invalid start byte
Past=pd.read_csv("C:/Users/.../Past.csv",encoding='utf-8')
Past=pd.read_csv("C:/Users/.../Past.csv",encoding='cp1252')
UTF-8 -> cp1252
그래도 다른 에러가 뜨면?
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 596: character maps to <undefined>
pd.read_csv("Your filename", encoding="ISO-8859-1")
'공부 > 개발' 카테고리의 다른 글
Flutter Design Pattern (0) | 2023.03.09 |
---|---|
[NLP] 식물 아닌 모델 관찰일지 (0) | 2022.07.26 |
[Azure] Cognitive Service for Language 텍스트 분석 사용하기 (0) | 2022.02.02 |
[AWS] RDS 데이터베이스 삭제 (0) | 2021.12.21 |
TypeError: Cannot read properties of undefined (reading 't') at VueComponent.listData (0) | 2021.11.18 |