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


Python/Pandas

(18)
[Pandas] Dataframe ์ธ๋ฑ์Šค to list ๋ณ€ํ™˜ to_list() ์‚ฌ์šฉ >>> idx = pd.Index([1, 2, 3]) >>> idx Index([1, 2, 3], dtype='int64') >>> idx.to_list() [1, 2, 3] https://pandas.pydata.org/docs/reference/api/pandas.Index.tolist.html pandas.Index.tolist — pandas 2.1.1 documentation Return the array as an a.ndim-levels deep nested list of Python scalars. pandas.pydata.org
[Pandas] Dataframe ์ „์ฒด ์ถœ๋ ฅํ•˜๊ธฐ import numpy as np from sklearn.datasets import load_iris import pandas as pd # Loading irirs dataset data = load_iris() df = pd.DataFrame(data.data, columns = data.feature_names) display(df) import numpy as np from sklearn.datasets import load_iris import pandas as pd data = load_iris() df = pd.DataFrame(data.data, columns = data.feature_names) # The scope of these changes made to # pandas sett..
[Pandas] Dataframe ์†Œ์ˆ˜์  ๊ด€๋ จ pd.read_excel('d:/a.xlsx', dtype={'a': str}) read_excel ๋กœ 14.8, 14.3์„ ์ฝ์—ˆ๋Š”๋ฐ ์ด๋Ÿฐ์‹์œผ๋กœ ๋˜์–ด์„œ ๋ฐ˜์˜ฌ๋ฆผ์„ ํ•ด์ฃผ์—ˆ๋‹ค..
[Python] Pandas - Dataframe ํ•จ์ˆ˜ ๋ชจ์Œ merge result_df = pd.merge(df1, df2, how='left', on='key') result_df = pd.merge(df1, df2, how='left', left_on='name1', right_on='name2') drop column df.drop(columns=['datetime'], inplace=True) reset index df.reset_index(inplace=True, drop=True) new col with apply df['new_col'] = df.apply(lambda x: json.loads(x['loc'])['c'][1], axis=1) sort # ์—ด ์ด๋ฆ„ ์ˆœ์„œ axis=1 # ๋‚ด๋ฆผ์ฐจ์ˆœ ascending=False df.sort_values(b..
[Python] Pandas - Dataframe for ๋ฌธ ์กฐํšŒ for i, row in df.iterrows(): print(row['name']) # ๊ฐ’ ๋ณ€๊ฒฝ df.loc[i, 'name'] = 'Jenny'
[Python] Pandas - DataFrame ์ด์ƒ์น˜ ์ œ๊ฑฐ def dr_outlier(df): quartile_1 = df.quantile(0.25) quartile_3 = df.quantile(0.75) IQR = quartile_3 - quartile_1 condition = (df (quartile_3 + 1.5 * IQR)) condition = condition.any(axis=1) search_df = df[condition] return search_df, df.drop(search_df.index, axis=0) https://wikidocs.net/83562 ์œ„ํ‚ค๋…์Šค ์˜จ๋ผ์ธ ์ฑ…์„ ์ œ์ž‘ ๊ณต์œ ํ•˜๋Š” ํ”Œ๋žซํผ ์„œ๋น„์Šค wikidocs.net https://ko.khanacademy.org/ma..
[Python] Pandas - DataFrame ํŠน์ • ์—ด ์„ ํƒ df = df[['a', 'c']]
[Python] Pandas - DataFrame ์ธ๋ฑ์Šค reset ํ•˜๊ธฐ reset_index() ํ•จ์ˆ˜ ์‚ฌ์šฉ df ์ž์ฒด๋ฅผ reset ์ƒํƒœ๋กœ ์ €์žฅ : inplace=True # df ์ƒ์„ฑ df = pd.DataFrame({'a': [1,np.NaN,3,np.NaN,4,3,2]}) # NaN ๊ฐ’ ์ œ๊ฑฐ df = df.dropna() # index resetํ•˜๊ธฐ - ๊ธฐ์กด index ์ œ๊ฑฐ X df.reset_index(drop=False) # index resetํ•˜๊ธฐ - ๊ธฐ์กด index ์ œ๊ฑฐ O df.reset_index(drop=True) sort ๋‚ด๋ฆผ์ฐจ์ˆœ : ascending=False df ์ž์ฒด๋ฅผ ์ •๋ ฌ๋œ ์ƒํƒœ๋กœ ์ €์žฅ : inplace=True df.sort_values(by=['name'], inplace=True)