структура вашего набора данных неверна с ";" в конце каждой строки
import pandas as pd
df = pd.read_csv("data/file.csv", sep = ";")
df = df.drop(df.columns[[0, 5]], axis=1)
df.head()
Out:
POST ACCOUNT DATE COUNTER
0 (post 8) (women 4) 2 0
1 (post 13) (men 1) 3 1
2 (post 14) (women 7) 4 3
3 (post 8) (women 4) 4 5
4 (post 19) (men 12) 5 0
Обрезать имя столбца
В именах столбцов есть пробелы
dico = {}
for col in df.columns:
dico[col] = col.strip()
df = df.rename(dico, axis=1)
Разделить столбцы на два столбца
df['POST'] = df['POST'].str.replace('(','').str.replace(')','')
df[['TYPE','POST']] = df['POST'].str.split(expand=True,)
df['ACCOUNT'] = df['ACCOUNT'].str.replace('(','').str.replace(')','')
df[['GENDER','GEN_NB']] = df['ACCOUNT'].str.split(expand=True,)
df.head ()
| index | POST | ACCOUNT | DATE | COUNTER | TYPE | GENDER | GEN_NB |
|-------|------|---------|------|---------|------|--------|--------|
| 0 | 8 | women 4 | 2 | 0 | post | women | 4 |
| 1 | 13 | men 1 | 3 | 1 | post | men | 1 |
| 2 | 14 | women 7 | 4 | 3 | post | women | 7 |
| 3 | 8 | women 4 | 4 | 5 | post | women | 4 |
| 4 | 19 | men 12 | 5 | 0 | post | men | 12 |
import seaborn as sns
import matplotlib.pyplot as plt
fg = sns.FacetGrid(data=df, hue='GENDER', aspect=1.61)
fg.map(plt.scatter, 'DATE', 'COUNTER').add_legend()
post_list = ['8','13','14']
df2 = df[df['POST'].isin(post_list)]
for post in df2.POST.unique():
sns.lineplot(x='DATE',y='COUNTER', hue='GENDER', data=df2[df2.POST==post])
plt.show()
edit: файл data.csv содержит
; POST ; ACCOUNT ; DATE ; COUNTER ;
0 ; (post 8) ; (women 4) ; 2 ; 0 ;
1 ; (post 13) ; (men 1) ; 3; 1 ;
2 ; (post 14) ; (women 7) ; 4; 3 ;
3 ; (post 8) ; (women 4) ; 4 ; 5 ;
4 ; (post 19) ; (men 12) ; 5; 0 ;