파이썬. 데이터분석/Pandas61 Pandas DataFrame : agg, as_index df_mpg = mpg.groupby('drv', as_index = False).agg(mean_hwy = ('hwy', 'mean')) as_index = False로 해주면 옆에 index를 하나 만들어준다. 2022. 7. 30. Pandas DataFrame : query, assign, groupby, agg Do it 165~166p assign, agg로 column만들고, groupby로 정리. agg는 평균, 합같은걸 구할때 쓰고 assign은 저런식으로 사용 2022. 7. 26. Pandas DataFrame : pivot aggfunc 옵션정리 https://datascientyst.com/list-aggregation-functions-aggfunc-groupby-pandas/ List of Aggregation Functions(aggfunc) for GroupBy in Pandas In this article, you can find the list of the available aggregation functions for groupby in Pandas: * count / nunique – non-null values / count number of unique values * min / max – minimum/maximum * first / last - return first or last value per group datasci.. 2022. 7. 25. DataFrame : query 프로토타입 응용1 조건마다 괄호를 칠수도 있다. in을 사용할 수도 있고, DataFrame 외 변수를 사용할땐 @ 사용 응용2 ++추가 query문 쓰면 조금 짧아지고 직관적으로 바뀜 2022. 7. 24. Pandas DataFrame : int를 object로 변환 https://stackoverflow.com/questions/17950374/converting-a-column-within-pandas-dataframe-from-int-to-string Converting a column within pandas dataframe from int to string I have a dataframe in pandas with mixed int and str data columns. I want to concatenate first the columns within the dataframe. To do that I have to convert an int column to str. I've tried to do as stackoverflow.com df['A'] = .. 2022. 7. 21. DataFrame : object에서 ,(콤마) 지우고 integer로 바꾸기 데이터를 보면 ,가 적혀있는 object라서 데이터를 다루는데 제한이 좀 있다. df_m.iloc[0] = df_m.iloc[0].str.replace(',','').astype(int) 첫번째 행은 integer로 바뀌었다 열을 바꾸고 싶으면? (이제부터 데이터프레임을 df_m 대신 그냥 df라고 하겠습니다) 전체바꾸는법은 아직.. 찾고있는데 잘 모르겠습니다 ?? 2022. 7. 17. pd.read_excel : 경로는 고정, 파일명만 바꾸기 fileroute 경로는 고정시켜놓고 filename만 바꿔서하면 실무에서 편함 2022. 7. 16. Numpy : np.where / if 함수역할 df['sex'] = np.where(df['sex'] == 3, np.nan, df['sex']) df 예시1 mpg['grade2'] = np.where(mpg['total'] >= 30, 'A', np.where(mpg['total'] >= 25, 'B',np.where(mpg['total'] >= 20, 'C', 'D'))) mpg['size'] = np.where((mpg['category'] == 'compact') | (mpg['category'] == 'subcompact') | (mpg['category'] == '2seater'), 'small', 'large') mpg['size'] = np.where(mpg['category'].isin(['compact','subcompact','.. 2022. 7. 14. 이전 1 2 3 4 5 6 7 8 다음