相关疑难解决方法(0)

在pandas/python中的数据框中组合两列文本

我在使用pandas的python中有一个20 x 4000的数据帧.其中两列名为Year和quarter.我想创建一个名为period的变量,将Year = 2000和quarter = q2变为2000q2

任何人都可以帮忙吗?

python numpy dataframe pandas

395
推荐指数
17
解决办法
60万
查看次数

将pandas dataframe中的列从int转换为string

我在pandas中有一个带有混合int和str数据列的数据帧.我想先连接数据框中的列.要做到这一点,我必须将int列转换为str.我试着这样做:

mtrx['X.3'] = mtrx.to_string(columns = ['X.3'])
Run Code Online (Sandbox Code Playgroud)

要么

mtrx['X.3'] = mtrx['X.3'].astype(str)
Run Code Online (Sandbox Code Playgroud)

但在这两种情况下它都不起作用,我收到的错误是"无法连接'str'和'int'对象".连接两str列是完美的.

python string int dataframe pandas

89
推荐指数
6
解决办法
25万
查看次数

标签 统计

dataframe ×2

pandas ×2

python ×2

int ×1

numpy ×1

string ×1