๋๋ delivery๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ์ง๊ณ ์์ผ๋ฉฐ ์ธ์(delivery.columns)ํ ๋ ๋ค์์ ์ป์ต๋๋ค.
Index(['Complemento_endereรงo', 'cnpj', 'Data_fundaรงรฃo', 'Nรบmero',
'Razรฃo_social', 'CEP', 'situacao_cadastral', 'situacao_especial', 'Rua',
'Nome_Fantasia', 'last_revenue_normalized', 'last_revenue_year',
'Telefone', 'email', 'Capital_Social', 'Cidade', 'Estado',
'Razรฃo_social', 'name_bairro', 'Natureza_Jurรญdica', 'CNAE', '#CNAE',
'CNAEs_secundรกrios', 'Pessoas', 'percent'],
dtype='object')
๊ธ์, ์ฐ๋ฆฌ๋ 'Rua'์ด์ด ์์์ ๋ถ๋ช ํ ์ ์ ์์ต๋๋ค.
๋ํ ์ธ์(delivery.Rua)ํ๋ฉด ์ ์ ํ ๊ฒฐ๊ณผ๋ฅผ ์ป์ต๋๋ค.
82671 R JUDITE MELO DOS SANTOS
817797 R DOS GUAJAJARAS
180081 AV MARCOS PENTEADO DE ULHOA RODRIGUES
149373 AL MARIA TEREZA
455511 AV RANGEL PESTANA
...
"delivery.columns: print('here I am')'์ if 'Rua'๋ผ๊ณ ์จ๋ 'here I am'์ด ์ธ์๋ฉ๋๋ค. ๊ทธ๋์ '๋ฃจ์'๊ฐ ์ค์ ๋ก ๊ฑฐ๊ธฐ์ ์์ต๋๋ค.
๊ธ์, ๋ด๊ฐ์ด ์ฝ๋๋ฅผ ๊ฐ์ง๊ณ ๋ฐ๋ก ๋ค์ ์ค์ :
delivery=delivery.set_index('cnpj')[['Razรฃo_social','Nome_Fantasia','Data_fundaรงรฃo','CEP','Estado','Cidade','Bairro','Rua','Nรบmero','Complemento_endereรงo','Telefone','email','Capital_Social', 'CNAE', '#CNAE', 'Natureza_Jurรญdica','Pessoas' ]]
๊ทธ๋ฆฌ๊ณ ์ง์, ์ด์ํ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
Traceback (most recent call last):
File "/file.py", line 45, in <module>
'Telefone', 'email', 'Capital_Social', 'Cidade', 'Estado',
'Razรฃo_social', 'name_bairro', 'Natureza_Jurรญdica', 'CNAE', '#CNAE',
'Telefone','email','Capital_Social', 'CNAE', '#CNAE', 'Natureza_Jurรญdica','Pessoas' ]]
'CNAEs_secundรกrios', 'Pessoas', 'percent'],
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/frame.py", line 1991, in __getitem__
dtype='object')
return self._getitem_array(key)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/frame.py", line 2035, in _getitem_array
indexer = self.ix._convert_to_indexer(key, axis=1)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pandas/core/indexing.py", line 1214, in _convert_to_indexer
raise KeyError('%s not in index' % objarr[mask])
KeyError: "['Rua'] not in index"
๋๊ตฐ๊ฐ ๋์ธ ์ ์์ต๋๊น? ๋๋ stackoverflow๋ฅผ ์๋ํ์ง๋ง ์๋ฌด๋ ๋์ธ ์ ์์์ต๋๋ค. ๋๋ ๋ด๊ฐ ๋ฏธ์ณค๋ค๊ณ ์๊ฐํ๊ธฐ ์์ํ๊ณ 'Rua'๋ ๋ด ํผ๋์ค๋ฌ์ด ๋ง์์ ํ์์ ๋๋ค.
์ถ๊ฐ ์ ๋ณด
์ค๋ฅ ์ค ๋ฐ๋ก ์์์ด ์ฝ๋๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค.
delivery=pd.DataFrame()
for i in selection.index:
sample=groups.get_group(selection['#CNAE'].loc[i]).sample(selection['samples'].loc[i])
delivery=pd.concat((delivery,sample)).sort_values('Capital_Social',ascending=False)
print(delivery.columns)
print(delivery.Rua)
print(delivery.set_index('cnpj').columns)
delivery=delivery.set_index('cnpj')[['Razรฃo_social','Nome_Fantasia','Data_fundaรงรฃo','CEP','Estado','Cidade','Bairro','Rua','Nรบmero','Complemento_endereรงo',
'Telefone','email','Capital_Social', 'CNAE', '#CNAE', 'Natureza_Jurรญdica','Pessoas' ]]
ํธ์งํ๋ค
์๋ก์ด ์ด์ํ ๊ฒ๋ค:
๋๋ ๊ทธ๊ฒ์ด ์๋ํ๊ธฐ๋ฅผ ๋ฐ๋ผ๋ ๋ง์ง๋ง ์ฝ๋์์ 'Rua'๋ฅผ ํฌ๊ธฐํ๊ณ ์ญ์ ํ์ต๋๋ค. ๋๋๊ฒ๋ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์์ง๋ง ์ด์ ๋ 'Nรบmero' ์ด์ด ์์ต๋๋ค.
delivery=delivery.set_index('cnpj')[['Razรฃo_social','Nome_Fantasia','Data_fundaรงรฃo','CEP','Estado','Cidade','Bairro','Nรบmero','Complemento_endereรงo',
'Telefone','email','Capital_Social', 'CNAE', '#CNAE', 'Natureza_Jurรญdica' ]]
KeyError: "['Nรบmero'] not in index"
ํธ์ง 2
๊ทธ๋ฌ๋ค '๋๋ฉ๋ก'๋ฅผ ํฌ๊ธฐํ๊ณ ๊บผ๋๋ค. ๊ทธ๋ฐ ๋ค์ 'Complemento_endereรงo'์์๋ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๊ทธ๋ฐ ๋ค์ 'Complemento_endereรงo'๋ฅผ ์ญ์ ํ์ต๋๋ค. ๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ 'Telefone' ๋ฑ์ ์ผ์ด๋ฌ์ต๋๋ค.
* ํธ์ง 3 *
pd.show_versions()๋ฅผ ์ํํ๋ฉด ๋ค์๊ณผ ๊ฐ์ด ์ถ๋ ฅ๋ฉ๋๋ค.
์ปค๋ฐ: ์์
ํ์ด์ฌ: 3.5.0.final.0
ํ์ด์ฌ ๋นํธ: 64
์ด์ ์ฒด์ : ๋ค์
OS ๋ฆด๋ฆฌ์ค: 16.5.0
๊ธฐ๊ณ: x86_64
ํ๋ก์ธ์: i386
๋ฐ์ดํธ ์ค๋: ์กฐ๊ธ
LC_ALL: ์์
๋: ์์
ํฌ๋: 0.18.1
์ฝ: ์์
ํ: 8.1.2
์ค์ ๋๊ตฌ: 18.2
์ฌ์ด์ฌ: ์์
์ซ์: 1.11.0
์ฌ์ดํผ: 0.17.1
ํต๊ณ ๋ชจ๋ธ: 0.6.1
xarray: ์์
IPython: ์์
์คํํฌ์ค: ์์
ํจํฐ: 0.4.1
๋ ์ง ์ ํธ๋ฆฌํฐ: 2.5.3
ํผ์ธ : 2016.4
๋ธ๋ก: ์์
๋ณ๋ชฉ ํ์: ์์
ํ
์ด๋ธ: ์์
numexpr: ์์
๋งคํธํ๋กฏ๋ฆฝ: 1.5.1
openpyxl: ์์
xlrd: 1.0.0
xlwt: ์์
xlsxwriter: ์์
lxml: ์์
bs4: 4.5.1
html5lib: ์์
httplib2: ์์
API ํด๋ผ์ด์ธํธ: ์์
sqlalchemy: 1.1.3
pymysql: 0.7.11.์์
psycopg2: ์์
jinja2: ์์
๋ณดํ : ์์
pandas_datareader: ์์
์์
@abutremutante : ์ ๊ณ ํด์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค! ์ ๋ง ์ด์ํด ๋ณด์ด์ง๋ง ์ฝ๋๋ฅผ ์คํํ ์ ์๊ธฐ ๋๋ฌธ์ ์ด ์์ ์์ ๋ณต์ ํ ์ ์์ต๋๋ค. ์์ ํ ์ฝ๋ ์ํ์ ์ ๊ณตํด ์ฃผ์๊ฒ ์ต๋๊น?
๋ํ ์ด๊ธฐ ๋ฐํ ์์์ pd.show_versons
์ ์ถ๋ ฅ์ ์ ๊ณตํ ์ ์๋ค๋ฉด ์ข์ ๊ฒ์
๋๋ค.
์๋
ํ์ธ์! ๋๋ต ํด์ค์ ๊ณ ๋ง์.
github์ ๊ณต๊ฐํ๊ณ ์ถ์ง ์์ต๋๋ค. ์ด๋ฉ์ผ๋ก ๋ณด๋ด๋๋ฆด๊น์?
Em 17 de ago de 2017, ร (s) 19:38, gfyoung [email protected] escreveu:
@abutremutante https://github.com/abutremutante : ์ ๊ณ ํด ์ฃผ์ ์ ๊ฐ์ฌํฉ๋๋ค! ์ ๋ง ์ด์ํด ๋ณด์ด์ง๋ง ์ฝ๋๋ฅผ ์คํํ ์ ์๊ธฐ ๋๋ฌธ์ ์ด ์์ ์์ ๋ณต์ ํ ์ ์์ต๋๋ค. ์์ ํ ์ฝ๋ ์ํ์ ์ ๊ณตํด ์ฃผ์๊ฒ ์ต๋๊น?
๋ํ ์ด๊ธฐ ๋ฐํ ์์์ pd.show_versons์ ์ถ๋ ฅ์ ์ ๊ณตํ ์ ์๋ค๋ฉด ์ข์ ๊ฒ์ ๋๋ค.
โ
๋น์ ์ด ์ธ๊ธ๋์๊ธฐ ๋๋ฌธ์ ์ด๊ฒ์ ๋ฐ๋ ๊ฒ์ ๋๋ค.
์ด ์ด๋ฉ์ผ์ ์ง์ ๋ต์ฅํ๊ฑฐ๋ GitHub https://github.com/pandas-dev/pandas/issues/17275#issuecomment-323213193 ์์ ํ์ธํ๊ฑฐ๋ https://github.com/notifications/unsubscribe-auth/ ์ค๋ ๋๋ฅผ ์์๊ฑฐ
์ด ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ค๋ ์ฌ๋์ ์ฝ๋๋ฅผ ๋ณผ ํ์๊ฐ ์์ผ๋ฏ๋ก ๊ฐ๊ธ์ ์ด๋ฉด ์ ๋ฉ๋๋ค. ๋ฏผ๊ฐํ ์ ๋ณด๊ฐ ํฌํจ๋์ง ์์ ๋ค๋ฅธ ํ
์ด๋ธ(๋๋ DataFrame
)๋ก ๋ณต์ ๋ฅผ ์๋ํ ์ ์์ต๋๊น?
์ฌ๊ธฐ์์ ์๋:
pandas๋ฅผ pd๋ก ๊ฐ์ ธ์ค๊ธฐ
import FindCos.FindCos_Functions as find #๊ทธ๊ฒ์ ๋ด๊ฐ ์ผ๋ถ ๊ธฐ๋ฅ์ ์์ฑํ๋ ํ์ผ์
๋๋ค
๋ ์ง ์๊ฐ ๊ฐ์ ธ์ค๊ธฐ
๊ฐ์ ธ์ค๊ธฐ pdb
target=find.get_full_basics(business='select * from sqltable;',test_mode=False)
CNAE=['23.30-3-01','26','27','49.30-2-03','37.02-9-00','46.45','47.73','46.44-3-01' ]
๊ณ ์ฉ๋_cos=200
์ ํ=pd.DataFrame()
CNAE์์ i์ ๊ฒฝ์ฐ:
x=target.loc[๋์['#CNAE'].str.startswith(i) == ์ฐธ]
์ ํ=pd.concat((์ ํ,x))
selection=selection.loc[selection['์๋ณธ_์์
'] < 100000000].loc[selection['situacao_cadastral'] == 'ATIVA']\
.loc[selection['situacao_especial'].isnull() == True].loc[selection['Natureza_Juridica'] != 'EMPRESA INDIVIDUAL DE RESP.LIMITADA(DE NATUREZA EMPRESARIA)']\
.loc[selection['Natureza_Juridica'] != 'EMPRESARIO(๊ฐ์ธ)']\
.loc[์ ํ['์์คํ๋'] != 'PA'].loc[์ ํ['์์คํ๋'] != '์ค์ ']\
.loc[์ ํ['์์คํ๋'] != 'RR'].loc[์ ํ['์์คํ๋'] != 'AC'].loc[์ ํ['์์คํ๋'] != 'RO'].loc[์ ํ[ '์์คํ๋'] != 'AP']\
.loc[selection['Estado'] != 'TO']
lista=['ํ์ผ.csv']
selection=find.exclude_business(selection,lista)
groups=selection.groupby('#CNAE')
์ ํ['๋ฐฑ๋ถ์จ']=๊ทธ๋ฃน['#CNAE'].transform('ํฌ๊ธฐ')/len(์ ํ)
์ ํ=์ ํ[['#CNAE','๋ฐฑ๋ถ์จ']].drop_duplicates().sort_values('๋ฐฑ๋ถ์จ',์ค๋ฆ์ฐจ์=๊ฑฐ์ง)
์ ํ['์ํ']=round(((hired_cos 1.05) ์ ํ['ํผ์ผํธ']))
๋ฐฐ๋ฌ=pd.DataFrame()
selection.index์์ i์ ๊ฒฝ์ฐ:
sample=groups.get_group(selection['#CNAE'].loc[i]).sample(selection['samples'].loc[i])
delivery=pd.concat((delivery,sample)).sort_values('Capital_Social',ascending=False)#.rename(columns={'Capital_Social':'Score_Tamanho'})
์ธ์(delivery.columns)
์ธ์(๋ฐฐ๋ฌ.๋ฃจ์)
print(delivery.set_index('cnpj').columns)
delivery=delivery.rename(columns={'๋ฃจ์':'๋ฃจ์'})
delivery.columns์ 'Rua'์ธ ๊ฒฝ์ฐ:
print('์ฌ๊ธฐ ์์ต๋๋ค')
delivery=delivery.set_index('cnpj')[['cnpj','Razao_social','Nome_Fantasia','Data_fundacao','CEP','Estado','Cidade','Bairro','Rua','Numero ','Complemento_endereco','Telefone','email','Capital_Social','CNAE','#CNAE','Natureza_Juridica']]
@abutremutante : ๊ณ ๋ง์ง๋ง ๋ถํํ๋ ์ด ์ฝ๋๋ ๋ณต์ ํ ์ ์์ต๋๋ค. import FindCos.FindCos_Functions
์คํํ ์ ์์ต๋๋ค. DataFrame
๋ฅผ ์ฒ์๋ถํฐ ์์ฑํ๊ณ ๋ฌธ์ ๋ฅผ ๋ณต์ ํด ๋ณด์ญ์์ค.
๋ํ ์ด๊ธฐ ๋ฐํ ์์์ pd.show_versons์ ์ถ๋ ฅ์ ์ ๊ณตํ ์ ์๋ค๋ฉด ์ข์ ๊ฒ์ ๋๋ค.
@gfyoung : ์ด๊ธฐ ๋ฐํ
๋ฐ์ดํฐ ํ๋ ์๊ณผ ๊ด๋ จํ์ฌ ์๋นํ ๊ธด ๋ฐ์ดํฐ ํ๋ ์์
๋๋ค. ๋๋ ๋ฐ๋ก ์ฌ๊ธฐ์์ 10๊ฐ์ ์ฒซ ๋ฒ์งธ ์ค์ ์ฌ์ฉํ์ฌ csv๋ฅผ ๋ง๋ค์์ต๋๋ค.
target=find.get_full_basics(business='select * from sqltable limit 10;',test_mode=False)
target.to_csv('target10items.csv')
์ฌ๊ธฐ์ ์ฒจ๋ถํฉ๋๋ค.
target10items.csv.zip
1) ์ด ๋ ์์ DataFrame
์ฌ์ฉํ์ฌ ๋ฌธ์ ๋ฅผ ๋ณต์ ํ ์ ์์ต๋๊น?
2) pandas
(ํ์ฌ 0.20.3
์์)์ ์์ฃผ ์ค๋๋ ๋ฒ์ ์ ์ฌ์ฉํ๊ณ ์๋ ๊ฒ์ผ๋ก ๋ํ๋ฌ์ต๋๋ค. ์
๊ทธ๋ ์ด๋๋ฅผ ์๋ํ๊ณ ๋ฌธ์ ๊ฐ ํด๊ฒฐ๋๋์ง ํ์ธํ ์ ์์ต๋๊น?
'Bairro'๋ print(delivery.columns)
์ ๋ํ ์ถ๋ ฅ์๋ ์์ง๋ง set_index
๋ค์์ ์ ๊ณตํ๋ ๋ชฉ๋ก์๋ ์์ต๋๋ค. ๊ทธ ๋ชฉ๋ก์์ 'Rua' ๋ฐ๋ก ์์ 'Bairro'๊ฐ ๋ํ๋๋ ๊ฒ์ด ์กฐ๊ธ ์์ฌ์ค๋ฝ์ต๋๋ค. ๋๋ฝ๋ ์ด์ ์ ํํ๋ ์ค๋ฅ ๋ฉ์์ง์ ๋ฌธ์ ๊ฐ ์์ต๋๊น?
์ข์, ๋ฌธ์ ๋ 'Bairro'๊ฐ ์ค์ ๋ก ๋๋ฝ๋ ํค์ด์ง๋ง pandas 0.18.1
์ ์ค๋ฅ ๋ฉ์์ง๊ฐ ๋๋ฝ๋ ํค๋ก ์๋ชป๋ ํญ๋ชฉ์ ํ์ํ๋ ๋ฒ๊ทธ๊ฐ ์๋ค๋ ๊ฒ์
๋๋ค.
๋ค์ ์ฝ๋ ์ฌ์ฉ
import pandas as pd
import numpy as np
cols = pd.Index(['Complemento_endereรงo', 'cnpj', 'Data_fundaรงรฃo', 'Nรบmero',
'Razรฃo_social', 'CEP', 'situacao_cadastral', 'situacao_especial', 'Rua',
'Nome_Fantasia', 'last_revenue_normalized', 'last_revenue_year',
'Telefone', 'email', 'Capital_Social', 'Cidade', 'Estado',
'Razรฃo_social', 'name_bairro', 'Natureza_Jurรญdica', 'CNAE', '#CNAE',
'CNAEs_secundรกrios', 'Pessoas', 'percent'],
dtype='object')
delivery = pd.DataFrame(np.random.random(size=(5, len(cols))), columns=cols)
delivery = delivery.set_index('cnpj')[['Razรฃo_social','Nome_Fantasia','Data_fundaรงรฃo','CEP','Estado','Cidade','Bairro','Rua','Nรบmero','Complemento_endereรงo','Telefone','email','Capital_Social', 'CNAE', '#CNAE', 'Natureza_Jurรญdica','Pessoas' ]]
pandas 0.18.1
์์ ๋ค์ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
KeyError: "['Rua'] not in index"
๊ทธ๋ฌ๋ pandas 0.20.3
์์ ์์ ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
KeyError: "['Bairro'] not in index"
๋
๋ชป ๋ฐ์๋ค
๊ทธ๊ฒ
@jschendel
๊ฐ์ฌํฉ๋๋ค @gfyoung
์ ๋ง ๊ณ ๋ง์ต๋๋ค.
๋ฌธ์ ๊ฐ ํด๊ฒฐ๋ ๊ฒ ๊ฐ์์ ์ข ๋ฃํฉ๋๋ค.
์๋
ํ์ธ์
๋ฌธ์ ๋ฅผ ํด๊ฒฐํ ์ค์ง์ ์ธ ์์ด๋์ด๊ฐ ๋ณด์ด์ง ์์ต๋๋ค @gfyoung ์ ์ด๊ฒ์ ๋ซ์ต๋๊น? ๋๋ ์ฌ์ ํ์ด ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋ถ๋ง์ด ์์ต๋๋ค. ์ด ์ค๋ฅ์ ์ง์ณค์ต๋๋ค.
@wangxuesong29 ์ต์ํ์ ์๊ฐ ์์ต๋๊น? http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports
๋๋ ๋น์ ๊ณผ ๊ฐ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. OpenOffice ํ๋ก๊ทธ๋จ์์ .csv ํ์์ ๋ฐ์ดํฐ๋ฅผ ๋ณ๊ฒฝํ๋ฉด ์ค๋ฅ๊ฐ ๋ฐ์ํ๋ ๊ฒ์ ๊ด์ฐฐํ์ต๋๋ค. ๊ทธ ๋์ ์ธํฐ๋ท์์ ๋ฐ์ดํฐ๋ฅผ ๋ค์ด๋ก๋ํ๊ณ ๊ฐ๋จํ ๋ฉ๋ชจ์ฅ++ ํธ์ง๊ธฐ์์ ๋ฐ์ดํฐ๋ฅผ ํธ์งํ์ต๋๋ค. ๊ทธ๋ฌ๋ฉด ์ ์์ ์ผ๋ก ์๋ํฉ๋๋ค. ์ด ์๋ฃจ์ ์ด ๋์์ด ๋์ง ์์ ์๋ ์์ง๋ง .csv ํ์ผ์ ์ง์ํ๋ ํ ์คํธ ํธ์ง๊ธฐ๋ ํ๋ก๊ทธ๋จ์ ๋ณ๊ฒฝํด์ผ ํ ์๋ ์์ต๋๋ค.
์ค๋ฅ :
ํฌ๋ ๋ฒ์ 0.23.4
์์ ๋์ผํ ์ฝ๋๋ฅผ ๋จ๊ฒจ๋๊ณ ๋์ผํ ๋ฌธ์ ๊ฐ ๋ฐ์ํ๋ฉด
์ฝ๋๋ฅผ ์คํํ ํ ๋ค์์ ์ป์ต๋๋ค.
์์ธ์ ์๋ '์ด์'
์ฝ๋ :
`pandas๋ฅผ pd๋ก ๊ฐ์ ธ์ค๊ธฐ
numpy๋ฅผ np๋ก ๊ฐ์ ธ์ค๊ธฐ
cols = pd.Index(['Address_Complement', 'cnpj', 'Foundation_Date', '์ซ์',
'Corporate_reason', 'CEP', 'situacao_cadastral', 'situacao_especial', '๊ฑฐ๋ฆฌ',
'Fantasy_Name', 'last_revenue_normalized', 'last_revenue_year',
'์ ํ', '์ด๋ฉ์ผ', '์๋ณธ_์์
', '์', '์ฃผ',
'๊ธฐ์
_์ด์ ', '์ด๋ฆ_์ด์', '์์ฐ๋ฒ', 'CNAE', '#CNAE',
'Secondary_CNAE', '์ฌ๋', '๋ฐฑ๋ถ์จ'],
dtype='๊ฐ์ฒด')
๋ฐฐ๋ฌ = pd.DataFrame(np.random.random(ํฌ๊ธฐ=(5, len(cols))), ์ด=์ด)
delivery = delivery.set_index('cnpj')[['ํ์ฌ_์ด๋ฆ','ํํ์ง_์ด๋ฆ','์ฌ๋จ_๋ ์ง','์ฐํธ๋ฒํธ','์ฃผ','์','๋๋ค','๊ฑฐ๋ฆฌ','๋ฒํธ',' Address_Complement ','์ ํ', '์ด๋ฉ์ผ', 'Social_Capital', 'CNAE', '#CNAE', 'Legal_Nature','People' ]]
`
์ด๊ฒ์ ๋ฌด์์ด ์๋ชป๋์๋์ง ์์๋ณด๊ธฐ ์ํด Google์ ๊ฒ์ํ์ฌ ์ฌ๊ธฐ์ ๋์ฐฉํ ์ฌ๋๋ค์ ์ํ ๊ฒ์ ๋๋ค.
CSV ๋๋ XLSX๋ก ์์ ํ๋ ๊ฒฝ์ฐ ์ด ์ด๋ฆ์ ์์ด๋ ๋์ ๊ณต๋ฐฑ์ด ์๋์ง 100% ํ์ธํ์ญ์์ค.
CSV๋ฅผ ๊ฐ์ ธ์ฌ ๋ ์ด์ ๊ฐ์ ธ์ค๋ ๋ฐ ๋ฌธ์ ๊ฐ ์์์ ๋ฐ๊ฒฌํ์ต๋๋ค. df๋ฅผ csv๋ก ๋ด๋ณด๋ด๊ณ Excel์์ ์ด ๋ ํํ ๋๋ ์ ํ ๊ณต๋ฐฑ์ ๋ณผ ์ ์์ต๋๋ค. ๋ฉ๋ชจ์ฅ์ด๋ ๋ฉ๋ชจ์ฅ++๋ก ์ด์ด์ผ ํฉ๋๋ค.
๋ค์ ๋งํ์ง๋ง, ์ด๊ฒ์ Google ๊ฒ์์์ ์ฌ๊ธฐ์ ๋์ฐฉํ ์ฌ๋๋ค์ ์ํ ๊ฒ์ ๋๋ค. ์ฌ์ฉ ์ค์ธ csv, xlsx ๋๋ ๊ธฐํ ๋ฐ์ดํฐ ํ๋ ์ ํ์ผ ํ ํ๋ฆฟ์ ์ด ํค๋ ์ด๋ฆ์์ ๋ชจ๋ ์ ํ ๋ฐ ํํ ๊ณต๋ฐฑ์ด ์ ๊ฑฐ๋์๋์ง ํ์ธํฉ๋๋ค.
๋๋ ๋ํ์ด ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค.
์ด์ ์ด๋ฆ์ correctlz์ด์ง๋ง csv ํ์ผ๊ณผ ํจ๊ป seaborn์ ์ฌ์ฉํ ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค(๋ด ์ด์ ์ฐ๋ฆฌ์ ์ธ๋ฑ์ค์).
import seaborn as sns
import pandas as pd
Data = pd.read_csv('test.csv',delimiter=',')
sns.lmplot(x='predLabel', y='trueLabel', data=Data)
์ค๋ฅ ๋ฉ์์ง:
KeyError: "['predLabel' 'trueLabel'] ์ธ๋ฑ์ค์ ์์"
๋๋ ๊ฐ์ ๋ฌธ์ ๊ฐ์๋ค
์ด์ ์ด๋ฆ์ ์ ํํ์ง๋ง csv ํ์ผ๊ณผ ํจ๊ป seaborn์ ์ฌ์ฉํ ๋ ์ค๋ฅ๊ฐ ๋ฐ์ํฉ๋๋ค(๋ด ์ด์ด ์ธ๋ฑ์ค๋ฅผ ๋ฒ์ด๋ฌ์ต๋๋ค).
์จ๋ณธ์ sns๋ก ๊ฐ์ ธ์ค๊ธฐ
pandas๋ฅผ pd๋ก ๊ฐ์ ธ์ค๊ธฐ
DF =
pd.read_csv('lawma1.csv', index_col =[0, 1], ๊ตฌ๋ถ ๊ธฐํธ=', ')
sns.lmplot(x='WEEK1', y='FLEET', ๋ฐ์ดํฐ=df).savefig('law.png')
์ค๋ฅ ๋ฉ์์ง:
KeyError: "['FLEET'] ์ธ๋ฑ์ค์ ์์
๋๋์ด ์ค๋ฅ๊ฐ ์์๊ณ ์ "."์ด ์์๊ธฐ ๋๋ฌธ์ ๋ฐ์ํ์ต๋๋ค. ์ด ์ด๋ฆ์ ๋์์ ์ ๊ฑฐํ ํ์ ์๋ํ์ต๋๋ค.
podaci = pd.read_csv('data/fifa19a.csv', names=['id', 'ime', 'godine', 'ocjena', 'potencijal.', 'bodovi', 'stopalo', 'placa_tis_eur', 'cijena_mil_eur'])
"potencijal"๋์ ์ด๋ฐ ์์ด์์ต๋๋ค.
๋ฒ๊ทธ ์ผ ์ ์์ต๋๋ค.
๋๋ ๊ฐ์ ๋ฌธ์ ์ ์ง๋ฉดํ๊ณ ์์ต๋๋ค. ๋๋ ์ฌ์ง์ด print(X.columns)๋ฅผ ์ฌ์ฉํ๊ณ ์ธ๋ฑ์ค 'exposure_end'๋ฅผ ๋ณด์ฌ์ฃผ์์ง๋ง ๋ด๊ฐ ๊ทธ๊ฒ์ ์ฌ์ฉํ์ ๋ centroids_new=X.groupby(["clusters"]).mean()[[" Exposure_end","Duration"]] ์ธ๋ฑ์ค์ ์๋ 'exposure_end' ์ค๋ฅ๊ฐ ํ์๋ฉ๋๋ค. ์ง๋ 2์๊ฐ ๋์ ์ฌ๊ธฐ์ ๊ฐํ์ต๋๋ค. ๋์์ฃผ์ธ์.
๋ด ๋ฌธ์ ์ ๋ํ ํด๊ฒฐ์ฑ
์ ์ฐพ์์ต๋๋ค.
๋๋ centroids_new=X.groupby(["clusters"]).mean()[["exposure_end","Duration"]] ์์ ์ง์ ์ ์ฌ์ฉํ๊ณ ์์๋๋ฐ ์ด ์ง์ ์์ x.mean(axis=1)์ ์ฌ์ฉํ ๋ค์ ์ง์ ์ ์ฌ์ฉ
centroids_new=X.groupby(["clusters"]).mean()[["exposure_end","Duration"]] ํ๊ท ์์ด ์ ์๋ํ์ต๋๋ค. groupby์ ํจ๊ป ์๋ํ์ง ์์ ๋ ๋จ๊ณ๋ก ์ํํด์ผํ๊ธฐ ๋๋ฌธ์ ์ด์ ๋ฌธ์์ ์ถ์ ์ฌ์ฉํ ์ ์์์ต๋๋ค.
๊ทธ๋ฆฌ๊ณ ๊ทธ๊ฒ์ด ์ผ์ด๋ ์ฃผ๋ ๋ฌธ์ ๋ ์ถ์ด 1๋ก ์ค์ ๋์๋ค๋ ๊ฒ์
๋๋ค.
๋ฌธ์ ์ ๋ํ ํด๊ฒฐ์ฑ ์ ์ฐพ์๊ณ ์๋ฒฝํ๊ฒ ์๋ํฉ๋๋ค.
csv ํ์ผ์ด ' , ' ๋๋ ' ๋ก ๊ตฌ๋ถ๋์ด ์๋์ง ํ์ธํ์ญ์์ค. ' . ์ ๊ฒฝ์ฐ์๋ ๋ฐ์ดํฐ๊ฐ ' , '๋ก ๊ตฌ๋ถ๋์์ง๋ง ์ ๋ ' ; '.
๊ทธ๋์ ๊ฐ๋จํ ์ถ๊ฐ
Df= pd.read_csv('C:\Users\user\Desktop\data.csv', sep=", ")
"์ด"๊ณผ "์ด"
๋ ๊ฐ์ง ๋ค๋ฅธ ๊ฒ์ ๋๋ค. ์ฒซ ๋ฒ์งธ๋ ์์ ๊ณต๋ฐฑ์ด ์์ต๋๋ค. ๊ณต๊ฐ์ด ์๋ ๊ณณ์ ๊ณต๊ฐ์ ์ถ๊ฐํ๊ธฐ๋ง ํ๋ฉด ๋ฉ๋๋ค.
์:
df["column "]์ด ๋๋ฅผ ์ํด ์ผํ์ต๋๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด๊ฒ์ ๋ฌด์์ด ์๋ชป๋์๋์ง ์์๋ณด๊ธฐ ์ํด Google์ ๊ฒ์ํ์ฌ ์ฌ๊ธฐ์ ๋์ฐฉํ ์ฌ๋๋ค์ ์ํ ๊ฒ์ ๋๋ค.
CSV ๋๋ XLSX๋ก ์์ ํ๋ ๊ฒฝ์ฐ ์ด ์ด๋ฆ์ ์์ด๋ ๋์ ๊ณต๋ฐฑ์ด ์๋์ง 100% ํ์ธํ์ญ์์ค.
CSV๋ฅผ ๊ฐ์ ธ์ฌ ๋ ์ด์ ๊ฐ์ ธ์ค๋ ๋ฐ ๋ฌธ์ ๊ฐ ์์์ ๋ฐ๊ฒฌํ์ต๋๋ค. df๋ฅผ csv๋ก ๋ด๋ณด๋ด๊ณ Excel์์ ์ด ๋ ํํ ๋๋ ์ ํ ๊ณต๋ฐฑ์ ๋ณผ ์ ์์ต๋๋ค. ๋ฉ๋ชจ์ฅ์ด๋ ๋ฉ๋ชจ์ฅ++๋ก ์ด์ด์ผ ํฉ๋๋ค.
๋ค์ ๋งํ์ง๋ง, ์ด๊ฒ์ Google ๊ฒ์์์ ์ฌ๊ธฐ์ ๋์ฐฉํ ์ฌ๋๋ค์ ์ํ ๊ฒ์ ๋๋ค. ์ฌ์ฉ ์ค์ธ csv, xlsx ๋๋ ๊ธฐํ ๋ฐ์ดํฐ ํ๋ ์ ํ์ผ ํ ํ๋ฆฟ์ ์ด ํค๋ ์ด๋ฆ์์ ๋ชจ๋ ์ ํ ๋ฐ ํํ ๊ณต๋ฐฑ์ด ์ ๊ฑฐ๋์๋์ง ํ์ธํฉ๋๋ค.