To calculate the molecular formula, convert the mass ratio into molar ratio as follows:
mass ratio of O:C=2:1
molar mass of carbon is 12 g/mol and that of oxygen is 16 g/mol thus, number of moles can be calculated as follows:
n=\frac{m}{M}
calculating ratio,
O:C=\frac{2 g}{16 g/mol}:\frac{1 g}{12 g/mol}=\frac{1}{8}:\frac{1}{12}=12:8=3:2
thus, molecular formula will be C_{2}O_{3}