我有一个 Dataframe df
,其中包含一列events
-
|events|
|{'id': 109421132110384, 'created_at': datetime.datetime(2022, 11, 28, 11, 12, 50, tzinfo=tzutc()), 'in_reply_to_id': None, 'in_reply_to_account_id': None, 'sensitive': False, 'spoiler_text': '', 'visibility': 'public', 'language': 'en', 'uri': 'https://users/statuses/10942113190455'},'note':'<p>Google me. Now go to page 8. Nope, that\'s not me. Try page 12.</p><p>-------------------------------</p><p>Would talk about <a href="https://mastodon.world/tags/parenting" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>parenting</span></a> all day, if you let me.)</p>'|
|{'id': 109421132340384, 'created_at': datetime.datetime(2022, 11, 30, 11, 12, 50, tzinfo=tzutc()), 'in_reply_to_id': None, 'in_reply_to_account_id': None, 'sensitive': False, 'spoiler_text': '', 'visibility': 'public', 'language': 'en', 'uri': 'https://users/statuses/10942113190467'},'note':'<p>Google me. Now go to page 8. Nope, that\'s not me. Try page 12.</p><p>-------------------------------</p><p>Would talk about <a href="https://mastodon.world/tags/parenting" class="mention hashtag" rel="nofollow noopener noreferrer" target="_blank">#<span>parenting</span></a> all day, if you let me.)</p>'|
数据类型-
print(type(df['events'][0]))
<class 'str'>
print(type(df['events']))
<class 'pandas.core.series.Series'>
print(type(df))
<class 'pandas.core.frame.DataFrame'>
如何将字符串转换为字典类型?
1条答案
按热度按时间vyswwuz21#
您是否需要对列
type to dict
进行类型转换?Pandas中没有
type - dict
这种东西。这种字典类型的格式在Pandas中通常被认为是str or mixed
。通常根据我的知识,数据在Pandas中将被处理为向量-Intro to data structures #pandas。它只是一个以向量化格式存储的dict
序列。更简单地说-存储在数组中的字典永远不会成为dict,因为数组中的数据来自
Dict