Skip to content

Instantly share code, notes, and snippets.

View guerbai's full-sized avatar
🎯
Focusing

guerbai

🎯
Focusing
View GitHub Profile
@guerbai
guerbai / select_sub_dataframe.py
Created June 2, 2019 05:05
选取特定col与特定row生成子dataframe #Pandas
df = reviews.loc[[0, 1, 10, 100], ['country', 'province', 'region_1', 'region_2']]
@guerbai
guerbai / remove_categorical_cols.py
Created June 2, 2019 05:04
去掉所有categorical variables的列 #Pandas
drop_X_train = X_train.select_dtypes(exclude=['object'])
# or
num_X_train = X_train.drop(object_cols, axis=1)
@guerbai
guerbai / get_all_categorical_variables.py
Created June 2, 2019 05:03
获取所有的categorical variables #Pandas
s = (X_train.dtypes == 'object')
object_cols = list(s[s].index)
print("Categorical variables:")
print(object_cols)
@guerbai
guerbai / get_nan_num_by_col.py
Created June 2, 2019 05:03
获取各列nan的个数 #Pandas
missing_val_count_by_column = (df.isnull().sum())
print (missing_val_count_by_column[missing_val_count_by_column > 0])
@guerbai
guerbai / remove_nan_col.py
Created June 2, 2019 05:02
去掉有nan的列 #Pandas
cols_with_missing = [col for col in X_train.columns
if df[col].isnull().any()]
reduced_df = df.drop(cols_with_missing, axis=1)
@guerbai
guerbai / init_pandas.py
Created June 2, 2019 05:00
初始化dataframe #Pandas
df = pd.DataFrame(np.arange(12).reshape(3,4),
columns=['A', 'B', 'C', 'D'])
@guerbai
guerbai / dataframe_tail.py
Created June 2, 2019 04:25
看dataframe的最后几行 #Pandas
df.tail()
@guerbai
guerbai / figure_size.py
Created June 2, 2019 04:25
改变可视化图表大小 #可视化
plt.figure(figsize=(16,6))
@guerbai
guerbai / dataframe_time_index.py
Created June 2, 2019 04:24
生成dataframe时指定以日期为index #Pandas
fifa_data = pd.read_csv(fifa_filepath, index_col="Date", parse_dates=True)
@guerbai
guerbai / ignore_warning.py
Created June 2, 2019 04:23
去掉不在意的warning #Jupyter
import warnings # current version of seaborn generates a bunch of warnings that we'll ignore
warnings.filterwarnings("ignore")