반응형

참고: http://stackoverflow.com/questions/18194404/create-column-with-elif-in-pandas


특정 조건 주어서 pandas column 값 변경하기


def func(row):
    if row['mobile'] == 'mobile':
        return 'mobile'
    elif row['tablet'] =='tablet':
        return 'tablet' 
    else:
        return 'other'
 

df['combo'] = df.apply(func, axis=1) 

반응형
반응형

출처: http://stackoverflow.com/questions/12190874/pandas-sampling-a-dataframe


Pandas에서 random sampling 할 수 있도록 함수 제공 

- sample 함수이용

- df.sample(n=몇개의 row를 샘플할 것인지/sample 갯수 값)

반응형
반응형

출처: http://stackoverflow.com/questions/22019763/pandas-writing-dataframe-columns-to-csv

 

header = ["Time", "User", "IP Address"]
df.to_csv('output.csv', columns = header) 

 

- header라는 변수에 export하고 싶은 컬럼을 적어주면 원하는 컬럼만 csv로 export 할 수 있음

반응형

+ Recent posts