数据科学入门:基础、术语与案例解析
1. 前提技能与示例代码
在开始数据科学之旅前,假定你已具备基础的Python编码技能,包括识别和运用基本数据类型(如 int、float、布尔型等),能够轻松创建函数和类,并且熟练掌握逻辑运算符(如 ==、>=、<=)。
下面通过一个解析单条推文的示例来进一步说明。示例代码如下:
tweet = "RT @j_o_n_dnger: $TWTR now top holding for Andor, unseating $AAPL"
words_in_tweet = tweet.split(' ') # list of words in tweet
for word in words_in_tweet: # for each word in list
if "$" in word: # if word has a "cashtag"
print("THIS TWEET IS ABOUT", word) # alert the user
代码逐行解析如下:
1. 首先,设置一个变量 tweet 来存储文本(在Python中称为字符串),此例中推文内容为 “RT @robdv: $TWTR now top holding for Andor, unseating $AAPL”。
2. words_in_tweet 变量对推文进行分词(按单词分隔),若打印该变量,输出如下:
['RT', '@robdv:'
超级会员免费看
订阅专栏 解锁全文
7万+

被折叠的 条评论
为什么被折叠?



