top of page
  • Writer's pictureAdisorn O.

Panda's Cheat Sheet for ML



# Import the library

import pandas as pd


# Create a DataFrame

df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})


# Read a CSV file

df = pd.read_csv('file.csv')


# Select a single column

df['A']


# Select multiple columns

df[['A', 'B']]


# Select rows by their position

df[0:2]


# Select rows by their labels

df.loc[labels]


# Select rows by condition

df[df['A'] > 2]


# Apply a function to a column

df['A'].apply(np.sqrt)


# Group by a column

df.groupby('A').mean()


# Save a DataFrame to a CSV file

df.to_csv('file.csv')



pdf file :




3 views

Commenti


bottom of page