Advertisement
TitanOP

DL12L3W

May 1st, 2024
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.32 KB | Source Code | 0 0
  1. # Functions
  2. def check_nan_values(df):
  3.     nan_columns = df.columns[df.isnull().any()].tolist()
  4.  
  5.     if not nan_columns:
  6.         print("No NaN values found")
  7.     else:
  8.         print("NaN values found in: ")
  9.         for column in nan_columns:
  10.             print(f"{column}: {df[column].isnull().sum()} NaN values")
  11.            
  12. def bar_plot(variable):
  13.     # get feature
  14.     var = train_df[variable]
  15.     varValue = var.value_counts()
  16.    
  17.     # visualize
  18.     plt.figure(figsize = (9,3))
  19.     plt.bar(varValue.index, varValue)
  20.     plt.xticks(varValue.index, varValue.index.values)
  21.     plt.ylabel("Frequency")
  22.     plt.title(variable)
  23.     plt.show()
  24.     print("{}: \n {}".format(variable,varValue))
  25.    
  26. def pie_plot(variable):
  27.     # get feature
  28.     var = train_df[variable]
  29.     varValue = var.value_counts()
  30.    
  31.     varValue.plot.pie(autopct='%1.1f%%', textprops={'fontsize':12}).set_title("Frequency")
  32.     print("{}: \n {}".format(variable,varValue))
  33.    
  34. df['column'] = df['column'].fillna(value)
  35.  
  36. df.drop('a', axis=1, inplace=True)
  37.  
  38. df[['A', 'B']] = df['AB'].str.split(' ', n=1, expand=True)
  39.  
  40. df.iloc[0:2, df.columns.get_loc('Taste')] = 'good' (row, col)
  41.  
  42. # Select Columns 'B' through 'D'
  43. selected_columns = df.loc[:, 'B':'D']
  44.  
  45. # Select Rows Between 'Row_2' and 'Row_4'
  46. selected_rows = df.loc['Row_2':'Row_4']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement