@sidonduarte/

pandas-itertuples

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import pandas as pd 

raw_data = {'regiment': ['Nighthawks', 'Nighthawks', 'Nighthawks', 'Nighthawks'],
            'company': ['1st', '1st', '2nd', '2nd'],
            'deaths': ['kkk', 52, '25', 616],
            'battles': [5, 42, 2, 2],
            'size': ['l', 'll', 'l', 'm']}
df = pd.DataFrame(raw_data, columns = ['regiment', 'company', 'deaths', 'battles', 'size'])

df['com_zeros'] = '0'

print(df)

for b in df.itertuples():
    df.com_zeros[b.Index] = '0'+str(b.battles) if b.battles<9 else str(b.battles)
    
print(df)