我想使用 python 将单元格中包含的数据拆分为多行。下面给出了这样的一个例子:
这是我的数据:
fuel cert_region veh_class air_pollution city_mpg hwy_mpg cmb_mpg smartway
ethanol/gas FC SUV 6/8 9/14 15/20 1/16 yes
ethanol/gas FC SUV 6/3 1/14 14/19 10/16 no
Run Code Online (Sandbox Code Playgroud)
我想把它转换成这种形式:
fuel cert_region veh_class air_pollution city_mpg hwy_mpg cmb_mpg smartway
ethanol FC SUV 6 9 15 1 yes
gas FC SUV 8 14 20 16 yes
ethanol FC SUV 6 1 14 10 no
gas FC SUV 3 14 19 16 no
Run Code Online (Sandbox Code Playgroud)
以下代码返回错误:
import numpy as np
from itertools import chain
# return …Run Code Online (Sandbox Code Playgroud)