python 基础

一、 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.csdn.net/houhuipeng/article/details/90416494

 https://blog.csdn.net/wxy_csdn_world/article/details/80759915

 其它

1. python list 统计词频 

https://blog.csdn.net/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')

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

微知girl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值