下面是我的代码:
dfFact = pd.read_sql_query("select * from MusicFact;", conn)
dfFact['artist'].fillna(0)
dfFact['artist'].astype('Int64')
dfFact['artist'] = dfFact['artist'].astype(str)I am trying to convert the following dataframe into a string dataframe
例如,我想要的输出必须是'3','3','3','3','2','1','0','0‘
我被卡住了,所以我想我应该来堆栈--提前谢谢你!
发布于 2020-06-02 16:01:04
如果在不使用inplace=True的情况下使用Series.fillna,则会返回一个新序列,其中包含用替换值填充的缺失值。类似地,Series.astype返回一个强制转换系列的副本。在您的示例中,您没有将这些操作的结果分配回序列,因此更改不会在输出中传播。
简单地,使用:
dfFact['artist'] = dfFact['artist'].fillna(0).astype(int).astype(str)https://stackoverflow.com/questions/62147223
复制相似问题