一、 pandas
1. DataFrame
df=df[(df["sentiment"].isin(["正面","负面","中性","有正有负"]))]
df=df[(df["domain"].isin(["相关"]))]
df['sentiment']=df['sentiment'].replace(["有正有负"],["负面"])
>>> df.isnull().sum()
commentcount 114
content 1406
favoritecount 981
keyword 974
likecount 2152
posterscreenname 2321
publishdatestr 2218
sharecount 2218
tags 44426
title 2337
topics 19046
viewcount 3462
dtype: int64
>>> len_df = df.content.str.len()
>>> print(len_df.describe())
count 49568.000000
mean 500.855996
std 504.115289
min 1.000000
25% NaN
50% NaN
75% NaN
max 17185.000000
Name: content, dtype: float64
>>> keywords = df.keyword.tolist()
>>> pd.value_counts(keywords)
二、 numpy
1. Np.array() 和np.asarray()区别
当数据源是ndarray时,array会copy出一个副本,占用新的内存,但asarray不会。
三、 运算符
1. 右移
例:a = 10 a >> 1 # a = 5
原理:a的二进制: 1010 向右移一位-> 0101 转为十进制:5
左移 <<
例: 10 << 1 # 20
原理:直接在末尾补0 1010 左移一位 10100 结果 20
注:有一种简单的计算方式,
对于右移运算,结果为 num// 2**count,即当前数值除以2的n次方取整。
对于右移运算,结果为 num * 2**count,即当前数值乘以2的n次方。
2. 其它
https://blog.youkuaiyun.com/houhuipeng/article/details/90416494
https://blog.youkuaiyun.com/wxy_csdn_world/article/details/80759915
其它
1. python list 统计词频
https://blog.youkuaiyun.com/qq_41911048/article/details/89227758
Import pandas as pd
Pd.value_counts(list)
From collections import Counter
Temp = Counter(list) # 词典结果
2. Uuid 可以生成唯一id, 根据时间和设备等信息得到 Attpr.id
3. 时间戳 timestamp = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')