파이썬 How to quickly parse a list of strings
구분 문자로 구분 된 단어 목록을 분할하려면 다음을 사용할 수 있습니다. >>> 'abc,foo,bar'.split(',') ['abc', 'foo', 'bar'] 하지만 구분 기호 문자를 포함 할 수있는 인용 문자열도 처리하려면 어떻게 쉽고 빠르게 동일한 작업을 수행 할 수 있습니까? In: 'abc,"a string, with a comma","another, one"' Out: ['abc', 'a string, with a comma', 'another, one'] 해결 방법 import csv input = ['abc,"a string, with a comma","another, one"'] parser = csv.reader(input) for fields in parser: for i,f in..
2020. 11. 14.
파이썬 팬더의 크기와 개수의 차이점은 무엇입니까?
이것이 pandas에서 groupby ( "x"). count 와 groupby ( "x"). size 의 차이점입니까? 크기는 nil을 제외합니까? 해결 방법 In [46]: df = pd.DataFrame({'a':[0,0,1,2,2,2], 'b':[1,2,3,4,np.NaN,4], 'c':np.random.randn(6)}) df Out[46]: a b c 0 0 1 1.067627 1 0 2 0.554691 2 1 3 0.458084 3 2 4 0.426635 4 2 NaN -2.238091 5 2 4 1.256943 In [48]: print(df.groupby(['a'])['b'].count()) print(df.groupby(['a'])['b'].size()) a 0 2 1 1 2 2 Nam..
2020. 11. 14.
파이썬 Meaning of X = X[:, 1] in Python
이 파이썬 코드 조각을 연구하고 있습니다. 마지막 줄에서 X = X [:, 1] 은 무엇을 의미합니까? def linreg(X,Y): # Running the linear regression X = sm.add_constant(X) model = regression.linear_model.OLS(Y, X).fit() a = model.params[0] b = model.params[1] X = X[:, 1] 해결 방법 x = np.random.rand(3,2) x Out[37]: array([[ 0.03196827, 0.50048646], [ 0.85928802, 0.50081615], [ 0.11140678, 0.88828011]]) x = x[:,1] x Out[39]: array([ 0.500486..
2020. 11. 14.