๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ


Python/Pandas

(18)
[Python] Pandas - Dataframe ๋ฆฌ์ŠคํŠธ ์ด์šฉํ•œ ํ•„ํ„ฐ : isin ์‚ฌ์šฉ
[Python] Pandas - Dataframe.merge()์—์„œ copy ์˜ต์…˜ pandas.merge(left, right, how='inner', on=None, left_on=None, right_on=None, left_index=False, right_index=False, sort=False, suffixes='_x', '_y', copy=True, indicator=False, validate=None) https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.merge.html pandas.merge — pandas 1.1.4 documentation If True, adds a column to the output DataFrame called “_merge” with information on the so..
[Python] Dataframe - row ์ถ”๊ฐ€ append ์‚ฌ์šฉ data = {'a': 123, 'b':34123} df = df.append(data)
[Python] Dataframe - iterrows for i, row in df.iterrows(): df.loc[i, 'a'] = 1 cnt = row['count']
[Python] Pandas - Dataframe, NaN ๊ฐ’ ์ฒ˜๋ฆฌ ๊ฒฐ์ธก๊ฐ’ ์žˆ๋Š” ํ–‰ ์‚ญ์ œ (axis=1 ๋˜๋Š” column ์ด๋ผ๊ณ  ํ•˜๋ฉด ์ปฌ๋Ÿผ ์‚ญ์ œ) df = df.dropna(axis = 0) df = df.reset_index(drop=True) ํŠน์ • ์—ด ์กฐ๊ฑด ์ฃผ๊ธฐ df.dropna(subset=['score']) 0์œผ๋กœ ๋ฐ”๊พธ๊ธฐ # 1 df.fillna(0) # 2 df.replace(np.NaN, 0)
[Python] Pandas - Dataframe, NaN ๊ฐฏ์ˆ˜ def cnt_nan(df): """์ „์ฒด ํ–‰ NaN ๊ฐฏ์ˆ˜ ์กฐํšŒ :param pandas.DataFrame df: dataframe :return: dataframe Example: ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์‚ฌ์šฉํ•˜์„ธ์š”: >>> cnt_nan(df) """ df_len = len(df) df = pd.DataFrame(df.isnull().sum()) df['%'] = (df[0]/df_len)*100 # ๋น„์œจ df = df.rename(columns = {0: 'NaN cnt'}) return df
[Python] Pandas - Dataframe, json ์œผ๋กœ ๋ณ€๊ฒฝ import pandas as pd df = pd.DataFrame({'a':152.0054343543, 'b':0.0070054423423, 'c':-7.54543543E-07, 'd':2.50282237391414E-11}, index=[0]) df.to_json(orient='records', double_precision=15) - to_json ์ด์šฉ - ์†Œ์ˆซ์  ์ž๋ฆฌ์ˆ˜ ๊ธฐ๋ณธ 10์ž๋ฆฌ๋ผ์„œ 15๋กœ ์„ค์ •ํ•จ date_format https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_json.html pandas.DataFrame.to_json — pandas 1.1.0 documentation The time unit..
[Python] Pandas - Dataframe ์ „์ฒด ํ–‰, ์—ด ๋ณด๊ธฐ ์„ค์ • pd.set_option('display.max_columns', None) pd.set_option('display.max_rows', None)