I have a .csv with US Congress biographical data that I read as a Panda df:
df = pd.read_csv('congress100.csv', delimiter = ';', names = ['Name', 'Position', 'Party', 'State', 'Congress'], header = 0)
My dataframe looks like this:
0 'ACKERMAN, Gary Leonard' 'Representative' 'Democrat' 'NY' '100(1987-1988)'
1 'ADAMS, Brockman (Brock)' 'Senator' 'Democrat' 'WA' '100(1987-1988)'
2 'AKAKA, Daniel Kahikina' 'Representative' 'Democrat' 'HI' '100(1987-1988)'
3 'ALEXANDER, William Vollie (Bill), Jr.' 'Representative' 'Democrat' 'AR' '100(1987-1988)'
4 'ANDERSON, Glenn Malcolm' 'Representative' 'Democrat' 'CA' '100(1987-1988)'
5 'ANDREWS, Michael Allen' 'Representative' 'Democrat' 'TX' '100(1987-1988)'
6 'ANNUNZIO, Frank' 'Representative' 'Democrat' 'IL' '100(1987-1988)'
7 'ANTHONY, Beryl Franklin, Jr.' 'Representative' 'Democrat' 'AR' '100(1987-1988)'
8 'APPLEGATE, Douglas Earl' 'Representative' 'Democrat' 'OH' '100(1987-1988)'
9 'ARCHER, William Reynolds, Jr.' 'Representative' 'Republican' 'TX' '100(1987-1988)'
10 'ARMEY, Richard Keith' 'Representative' 'Republican' 'TX' '100(1987-1988)'
I want to convert the data in the 'Congress' column to an integer. Right now, I am first converting it to a simpler string:
df['Congress'] = df['Congress'].str.replace(r'100\(1987-1988\)', '1987')
This is successful. But, I am then trying to convert that simpler string to an integer:
df['Congress'] = df['Congress'].pd.to_numeric(errors='ignore')
I am getting an error:
AttributeError: 'Series' object has no attribute 'pd'
Please help me resolve this error and simplify my code.