table.txt
quad lcid eid fx fy fxy QUAD 1 23 1.2 1.0 21.0 QUAD 4 24 2.6 2.0 22.0 QUAD 1 25 3.2 3.0 23.0 QUAD 2 23 4.6 4.0 24.0 QUAD 4 24 5.6 5.0 25.0 QUAD 2 25 6.2 6.0 26.0 QUAD 3 23 7.2 7.0 27.0 QUAD 3 24 6.2 8.0 28.0 QUAD 2 25 5.2 9.0 29.0 QUAD 4 23 3.3 10.0 30.0 QUAD 4 24 12.2 11.0 31.0 QUAD 1 25 1.1 12.0 32.0
ex333.py
import pandas as pd df = pd.read_csv("table.txt", sep=" ") print(df) df['max fx'] = df.groupby('eid')['fx'].transform('max') df['min fx'] = df.groupby('eid')['fx'].transform('min') print(df)
output:
quad lcid eid fx fy fxy 0 QUAD 1 23 1.2 1.0 21.0 1 QUAD 4 24 2.6 2.0 22.0 2 QUAD 1 25 3.2 3.0 23.0 3 QUAD 2 23 4.6 4.0 24.0 4 QUAD 4 24 5.6 5.0 25.0 5 QUAD 2 25 6.2 6.0 26.0 6 QUAD 3 23 7.2 7.0 27.0 7 QUAD 3 24 6.2 8.0 28.0 8 QUAD 2 25 5.2 9.0 29.0 9 QUAD 4 23 3.3 10.0 30.0 10 QUAD 4 24 12.2 11.0 31.0 11 QUAD 1 25 1.1 12.0 32.0 quad lcid eid fx fy fxy max fx min fx 0 QUAD 1 23 1.2 1.0 21.0 7.2 1.2 1 QUAD 4 24 2.6 2.0 22.0 12.2 2.6 2 QUAD 1 25 3.2 3.0 23.0 6.2 1.1 3 QUAD 2 23 4.6 4.0 24.0 7.2 1.2 4 QUAD 4 24 5.6 5.0 25.0 12.2 2.6 5 QUAD 2 25 6.2 6.0 26.0 6.2 1.1 6 QUAD 3 23 7.2 7.0 27.0 7.2 1.2 7 QUAD 3 24 6.2 8.0 28.0 12.2 2.6 8 QUAD 2 25 5.2 9.0 29.0 6.2 1.1 9 QUAD 4 23 3.3 10.0 30.0 7.2 1.2 10 QUAD 4 24 12.2 11.0 31.0 12.2 2.6 11 QUAD 1 25 1.1 12.0 32.0 6.2 1.1
Recent Comments