Reputation: 49
I am newbie to web scraping I am trying to scrape a table data from website after login. I wish to multiply 2nd column by 10.
Currently the table is writing to csv but what I actually want to work is to multiply 2nd column by 10 and write to csv
What I have tried is:
r2=session.post("http://www.example.com")
soup = BeautifulSoup(r2.text, "html.parser")
csvFile=open('Table.csv','w')
output = csv.writer(csvFile)
for table in soup.find_all('table')[5:]:
for row in table.find_all('tr'):
col = map(cell_text, row.find_all(re.compile('t[dh]')))
output.writerow(col)
output.writerow([])
csvFile.close()
For example if I have a table with data in website as:
Time Pressure Mass Temp
0.00 1.01 21 23.09
1.00 2.0908 21.1 10.07
2.0 2.8666 22.3 13.6
0.555 2.6545 2.4 32.56
The data for writing csv file should be:
0.00 10.1 21 23.09
1.00 20.908 21.1 10.07
2.0 28.666 22.3 13.6
0.555 26.545 2.4 32.56
How to do so?
Upvotes: 0
Views: 150
Reputation: 309
Its depends on how the elements are placed, here i have solution that you can apply it on csv.
import pandas as pd
df = pd.read_csv("Table.csv")
df.Pressure = df.Pressure * 10
df.to_csv("Table_Updated.csv",index=False)
df.to_csv("DataExport.csv",index=False,header=False) # Store without header
Upvotes: 2