|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
能不能把df.info()dtype中列名,是object与其它的分开打印出来或提出来 ?请大师帮忙,谢谢
import pandas as pd
data = [["2345", "A", "2022-12-20", "2.1016", "-0.72","2.8", "-0.77",78],
["004243", "C", "2022-12-15", "2.0891", ", 45","-0.77",98],
["519212", "B", "2022-12-10", "333", "1.9733", "-0.77", "-3.29",567],
["162411", "E", "2022-12-9", "0.7071", "-1.64","25", "-1.46",789],
["007844", "FC", "2022-11-19", "0.6967", '8', "88","-1.46",834.8],
["163208", "G", "2022-11-10", "1.0440", "-0.40","" ,"-0.40",0.568]]
columns = ["编号", "名称", "日期", "AA", "BB","CC","DD","EE"]
df = pd.DataFrame(data, columns=columns)
print(df.info())
object : "AA", "BB","CC","DD"
float64 : "EE"
本帖最后由 歌者文明清理员 于 2023-5-5 16:47 编辑
可以使用df.select_dtypes()方法来实现筛选想要的数据类型。示例如下:
``` import pandas as pd
data = [["2345", "A", "2022-12-20", "2.1016", "-0.72","2.8", "-0.77",78],
["004243", "C", "2022-12-15", "2.0891", ", 45","-0.77",98],
["519212", "B", "2022-12-10", "333", "1.9733", "-0.77", "-3.29",567],
["162411", "E", "2022-12-9", "0.7071", "-1.64","25", "-1.46",789],
["007844", "FC", "2022-11-19", "0.6967", '8', "88","-1.46",834.8],
["163208", "G", "2022-11-10", "1.0440", "-0.40","" ,"-0.40",0.568]]
columns = ["编号", "名称", "日期", "AA", "BB","CC","DD","EE"]
df = pd.DataFrame(data, columns=columns)
# 输出所有列的数据类型
print(df.dtypes)
# 输出object类型的列名
print(df.select_dtypes(include=['object']).columns.tolist())
# 输出非object类型的列名
print(df.select_dtypes(exclude=['object']).columns.tolist())
```
输出结果如下所示:
``` 编号 object
名称 object
日期 object
AA float64
BB object
CC object
DD object
EE float64
dtype: object
['编号', '名称', '日期', 'BB', 'CC', 'DD']
['AA', 'EE']
```
|
|