1 minute read

1. Read a excel file : read_excel()

import pandas as pd

df1= pd.read_excel("E05EXAMPLE.xlsx", sheet_name=1)
df1
Country Match Win Draw Lose Point GA
0 UAE 4 0 3 1 3 4
1 Korea 4 2 2 0 6 3
2 Syria 4 0 1 3 4 8
3 Iran 4 3 1 0 6 2
4 Iraq 4 0 3 1 4 5
5 Lebanon 4 1 2 1 3 4

2. Insert a row

df1["GP"] = df1["Win"]*3+df1["Draw"]
df1
Country Match Win Draw Lose Point GA GP
0 UAE 4 0 3 1 3 4 3
1 Korea 4 2 2 0 6 3 8
2 Syria 4 0 1 3 4 8 1
3 Iran 4 3 1 0 6 2 10
4 Iraq 4 0 3 1 4 5 3
5 Lebanon 4 1 2 1 3 4 5
df1["Difference"] = df1["Point"] - df1["GA"]
df1
Country Match Win Draw Lose Point GA GP Difference
0 UAE 4 0 3 1 3 4 3 -1
1 Korea 4 2 2 0 6 3 8 3
2 Syria 4 0 1 3 4 8 1 -4
3 Iran 4 3 1 0 6 2 10 4
4 Iraq 4 0 3 1 4 5 3 -1
5 Lebanon 4 1 2 1 3 4 5 -1

3. Delete a row

df2 = df1.drop(["Point","GA"], axis=1)
df2
Country Match Win Draw Lose GP Difference
0 UAE 4 0 3 1 3 -1
1 Korea 4 2 2 0 8 3
2 Syria 4 0 1 3 1 -4
3 Iran 4 3 1 0 10 4
4 Iraq 4 0 3 1 3 -1
5 Lebanon 4 1 2 1 5 -1

4. Copy to clipboard : to_clipboard()

df2.to_clipboard(index=False)

5. Total code

import pandas as pd

df1 = pd.read_excel("E05EXAMPLE.xlsx", sheet_name=1)
df1["GP"] = df1["Win"] * 3 + df1["Draw"]
df1["Difference"] = df1["Point"] - df1["GA"]

df2 = df1.drop(["Point", "GA"], axis=1)
df2.to_clipboard(index=False)

Updated: