Data Prog with Python
  • Introduction
  • Week2
  • Week3
  • Week4
  • Week5
  • Week6
  • Week7
  • Week8
  • Week9
  • Week10
  • project1
  • project2
  • project3
  • Useful codes for exam
Powered by GitBook
On this page
  • read and summary
  • missing values
  • replace a column and caculate mean by a group(column)
  • merge dataframe by a column
  • concat dataframe by rows
  • select rows by column value
  • split training and testing

Was this helpful?

Useful codes for exam

read and summary

df1=pd.read_csv('manu1(1).csv')
df1.describe()

missing values

df2=pd.read_csv('manu2(1).csv')
df2['material'].fillna('C',inplace=True)

replace a column and caculate mean by a group(column)

df2['ksize']=df2['ksize']+1
df2.groupby(['material']).mean()

merge dataframe by a column

df3 = pd.merge(df1, df2, on='ID')

concat dataframe by rows

df4=pd.read_csv('manu3(1).csv')
df5=pd.concat([df3,df4])

select rows by column value

df.loc[df['material'] == material]

split training and testing

from sklearn.model_selection import train_test_split
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
Previousproject3

Last updated 5 years ago

Was this helpful?