使用concat合并两个dataframe报错

版权声明:本文为博主原创文章,欢迎转赞,但请保留作者署名。 https://blog.csdn.net/DSTJWJW/article/details/83867048

使用concat合并两个dataframe报错

TypeError: cannot concatenate object of type "<class 'str'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid

显示说不能合并字符串类型的对象,我的两个df如下(都是显示前五行)

# df1
    latitude  longitude  status  grid_id
0       7497       3972       1     4120
6       7505       4208       1     4123
13      7717       4183       1     4302
17      7718       4183       1     4302
37      7524       4184       1     4182
# df2
    latitude  longitude  status  grid_id
5       7555       4143       2     4182
12      7517       4309       2     4124
16      7718       4182       2     4302
36      6176       3873       2     3159
54      7916       4124       2     4422

查看一下各列的类型

# print(df1.dtypes)
latitude     int32
longitude    int32
status        int8
grid_id      int64
dtype: object
# print(df2.dtypes)
latitude     int16
longitude    int16
status        int8
grid_id      int64
dtype: object

类型没有错啊,百思不得其解,然后仔细看了下自己写的代码

cab_df = pd.concat(['df1', 'df2'], ignore_index=True)

我擦,竟然将两个df用逗号括起来了,不出错才怪呢!

引以为戒,一定要注意细节!

猜你喜欢

转载自blog.csdn.net/DSTJWJW/article/details/83867048