1、数据转换(查看数据结果,看是否是所需要的)
生成表格
to_excel
,格式要求为 dataframe
报错显示↓
AttributeError: 'numpy.ndarray' object has no attribute 'to_excel'
var_sample=pd.DataFrame(var_sample)
var_sample.to_excel(r'D:\Desktop\var_sample.xlsx')
转换成list,或者数组
test=np.array(test)
2、看变量的类型
转自:https://www.zhihu.com/question/592560444/answer/2961251162
使用 type() 函数
type() 函数可以返回一个对象的类型。例如:
x = 42
print(type(x)) # 输出 <class 'int'>
使用 isinstance() 函数
isinstance() 函数可以检查一个对象是否属于某个特定的类或类型。例如:
x = "Hello, world!"
print(isinstance(x, str)) # 输出 True
需要注意的是,如果你想检查一个对象是否属于多个类或类型中的任意一个,可以将类型作为元组传递给 isinstance() 函数:x = 42
print(isinstance(x, (int, float))) # 输出 True这里,isinstance(x, (int, float)) 返回 True,因为 x 的类型是整数(int),而整数也是浮点数(float)的一种。
3、调用数据
1)series 类型数据
直接用 series[i] 就可以
2)numpy数组
用的是 numpy(i)
- Ty
peError: only list-like objects are allowed to be passed to isin(),
you passed a [int]原因:对dataframe进行筛选时筛选值是int,不能用df.isin(list)
解决:
df=df[column name].isin(list name) #筛选对象是list
df=df[df[column
name]==i] #筛选对象是int