import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
df = pd.read_csv('D:/7.文本类数据处理/aa.csv',encoding='gbk')
df.head(10)
| label | text_a |
---|
0 | 1.0 | 说 的 就是 你 |
---|
1 | 1.0 | 我 恨 你 不爱 你 了 |
---|
2 | 1.0 | 你 看 我 上线 太 让 我 伤心 了 不行 就 不行 |
---|
3 | 1.0 | 真是 让 人 讨厌 |
---|
4 | 2.0 | 赞 一个 ! 么 么 哒 |
---|
5 | 1.0 | 我 不 想 人家 说 你 闲话 |
---|
6 | 2.0 | 你 真好 我 有 你 谢谢 朋友 |
---|
7 | 1.0 | 可是 你 刚才 就 骗 我 了 |
---|
8 | 1.0 | 儿子 发烧 了 , 没 人 和 我 说话 , 心里 很 不是 滋味儿 |
---|
9 | 1.0 | 我 只是 很 愁 |
---|
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1200 entries, 0 to 1199
Data columns (total 2 columns):
label 1150 non-null float64
text_a 1150 non-null object
dtypes: float64(1), object(1)
memory usage: 18.8+ KB
df.isnull().any()
label True
text_a True
dtype: bool
df[df.isnull().values==True]
df.dropna(subset=['text_a','label'],axis=0,how='any',inplace=True)
df.isnull().any()
label False
text_a False
dtype: bool
df[df.duplicated('text_a')]
df.drop_duplicates(subset='text_a',keep='first',inplace=True)
df.duplicated('text_a').any()
False
plt.boxplot(x=df.label,
whis=1.5,
widths=0.7,
patch_artist=True,
showmeans=True,
boxprops={'facecolor':'steelblue'},
flierprops={'markerfacecolor':'red','markeredgecolor':'red','markersize':4},
meanprops={'marker':'D','markerfacecolor':'black','markersize':4},
medianprops={'linestyle':'--','color':'orange'},
labels=['']
)
plt.show()

q1 = df.label.quantile(q=0.25)
q3 = df.label.quantile(q=0.75)
low_whisker = q1-1.5*(q3-q1)
up_whisker = q3+1.5*(q3-q1)
df[df['label']==9.0]
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 1052 entries, 0 to 1199
Data columns (total 2 columns):
label 1052 non-null float64
text_a 1052 non-null object
dtypes: float64(1), object(1)
memory usage: 24.7+ KB
plt.rcParams['axes.unicode_minus']=False
df.label.value_counts()
1.0 682
2.0 320
6.0 50
Name: label, dtype: int64
plt.rcParams['font.sans-serif']=['KaiTi']
labels = ['中性','喜欢','悲伤','厌恶','快乐','生气','惊喜','恐惧']
sizes = [8055,1202,816,694,702,985,306,112]
fig,ax = plt.subplots()
ax.pie(sizes,labels=labels,autopct='%1.1f%%',shadow=False,startangle=150)
ax.set_title('bili')
plt.show()

df.to_csv('C:/aa2.csv',index=False,encoding='utf-8_sig')