‘DataFrame’ object has no attribute ‘dtype’或者’DataFrame’ object has no attribute ‘str’

使用pandas学习数据分析时报错

原因 :使用函数str.strip()去除空格和函数dtype()查看数据类型时, 只能一次对一列进行操作
解决 :使用循环语句。

df1 = df.copy()         #复制一份文件,防止意外
a1 = list(df.columns)
df[a1]= df1[a1].astype(str)         #转换为str类型
for i in a1:
    df[i] = df[i].str.strip()           #去除两边空格
df.dropna(axis=0,how='any') #drop all rows that have any NaN values
删除NaN所在的列:
删除表中全部为NaN的行
df.dropna(axis=1,how='all') 
删除表中含有任
                                    numpy.array可使用 shape。list不能使用shape。
可以使用np.array(list A)进行转换。
(array转list:array B B.tolist()即可)
补充知识:Pandas使用DataFrame出现错误:AttributeError: ‘list’ object has no attribute ‘astype’
在使用Pandas的DataFrame时出现了错误:AttributeError: ‘list’ object has no attribute ‘astype’
代码入下:
import pandas as pd
pop = {'Neva
from pandas import DataFrame
1、使用二维数组创建
df1=DataFrame(np.random.randint(0,10,(4,4)),index=[1,2,3,4],columns=['a','b','c','d'])
print(df1)
创建了一个4行4列由0-10随机整数组成的二维数组
列名为a、b、c、d
索引为:1、2、3、4
输出结果为:
2、使用字典创建
dict={
    'province':['Gua
                                    在运行嵩天老师python爬虫课中单元6中的实例“中国大学排名爬虫”会出现如下图错误:AttributeError: ‘NoneType’ object has no attribute ‘children’
意思是  ‘NoneType’ 对象没有属性 ‘children’  ,这个错误说明’children’ 属性的对象 soup 是一个空类型,那就意味着soup = BeautifulSoup(html,‘html.parser’)中soup并没有得到解析出来的html页面,那就是说在调用getHTMLText(url)函数时这个函数并没有得到url链接对应的网页信息。错误就出在get
运行这段代码时报错'DataFrame' object has no attribute 'str'
原因是我读入的数据是DataFrame格式,只需将数据添加一个列名names=['txt']即可,然后将上述代码改为:
data_len = data_null_comments[data_null_comments['txt'].st..
                                    这个错误消息的意思是,在你的代码中,你试图访问一个Pandas DataFrame对象的'dtype'属性,但该对象并没有这个属性。在Pandas中,DataFrame没有'dtype'属性,你可以使用'dtypes'属性来获取DataFrame中列的数据类型。请检查你的代码并确保使用正确的属性名称。
symbol_info_columns = ['1', '持仓方向', '持仓量', '持仓收益率', '持仓收益', '持仓均价', '当前价格', '最大杠杆']  # v3
symbol_config = {'BTC': 'BTC-USDT-210924', 'LTC': 'LTC-USDT-210924', 'EOS': 'EOS-USDT-210924', 'ETH': 'ETH-USDT-210924', 'XRP': '