Поиск оставшихся строк в кадрах данных pandasPython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Поиск оставшихся строк в кадрах данных pandas

Сообщение Anonymous »

Если я обнаруживаю Y в определенных столбцах, используя это:
thing1 = df[df['column1'] == 'Y']

thing2 = df[df['column2'] == 'Y']

thing3 = df[df['column3'] == 'Y']

thing4 = df[df['column4'] == 'Y']

Как получить все строки без буквы Y в одном из этих столбцов? Я пробовал что-то вроде:
none_of_the_things = df[(df['column1'] != 'Y') & (df['column2'] != 'Y') & (df[df['column3'] != 'Y']) & (df[df['column4'] != 'Y'])]

но это не работает. С такой ошибкой:
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 23.3 TiB for an array with shape (1855862, 1724897) and data type float64
python ./deepseek-v2.5-chart.py 11.91s user 2.81s system 105% cpu 13.996 total

Создал ли я этим методом какого-то монстра? 23,3 ТиБ звучит очень много.
пример csv:
RECVDATE,column1,column2,column3,column4
01/01/2024,Y,N,N,N
01/04/2024,N,N,N,N
02/02/2024,N,Y,N,N
02/02/2024,N,Y,N,N
02/04/2024,N,N,N,N
03/03/2024,N,N,Y,N
03/03/2024,N,N,Y,N
03/03/2024,N,N,Y,N
03/04/2024,N,N,N,N
04/04/2024,N,N,N,Y
04/04/2024,N,N,N,Y
04/04/2024,N,N,N,Y
04/04/2024,N,N,N,Y
04/04/2024,N,N,N,Y
04/04/2024,N,N,N,Y
04/04/2024,N,N,N,N
04/04/2024,N,N,N,N

пример Python с закомментированными ошибками:
#!/usr/bin env python3
date_field = 'RECVDATE'
import glob, os
import pandas as pd
import matplotlib.pyplot as plt
from datetime import datetime
dir_path = 'data'
dfs = [pd.read_csv(f, encoding='latin-1', low_memory=False, quotechar='"') for f in glob.glob(os.path.join(dir_path, 'example.csv'))]
df = pd.concat(dfs, axis=0, ignore_index=True)
df[date_field] = pd.to_datetime(df[date_field], errors='coerce')

thing1 = df[df['column1'] == 'Y']
thing1['YearMonth'] = thing1[date_field].dt.to_period('M')
monthly_counts1 = thing1.groupby('YearMonth').size()
monthly_counts1.index = monthly_counts1.index.astype(str)

thing2 = df[df['column2'] == 'Y']
thing2['YearMonth'] = thing2[date_field].dt.to_period('M')
monthly_counts2 = thing2.groupby('YearMonth').size()
monthly_counts2.index = monthly_counts2.index.astype(str)

thing3 = df[df['column3'] == 'Y']
thing3['YearMonth'] = thing3[date_field].dt.to_period('M')
monthly_counts3 = thing3.groupby('YearMonth').size()
monthly_counts3.index = monthly_counts3.index.astype(str)

thing4 = df[df['column4'] == 'Y']
thing4['YearMonth'] = thing4[date_field].dt.to_period('M')
monthly_counts4 = thing4.groupby('YearMonth').size()
monthly_counts4.index = monthly_counts4.index.astype(str)

# none_of_the_things = df[(df['column1'] != 'Y') & (df['column2'] != 'Y') & (df[df['column3'] != 'Y']) & (df[df['column4'] != 'Y'])]
# none_of_the_things['YearMonth'] = none_of_the_things[date_field].dt.to_period('M')
# non_monthly_counts = none_of_the_things.groupby('YearMonth').size()
# non_monthly_counts.index = non_monthly_counts.index.astype(str)

# Plotting
plt.figure(figsize=(12, 6))
monthly_counts1.plot(kind='line', marker='o', label='count1', color='red')
monthly_counts2.plot(kind='line', marker='o', label='count2', color='blue')
monthly_counts3.plot(kind='line', marker='o', label='count3', color='green')
monthly_counts4.plot(kind='line', marker='o', label='count4', color='purple')
# non_monthly_counts.plot(kind='line', marker='o', label='none', color='black')
plt.title('Number of Deaths/LifeThreating/Hospitalizations per Month')
plt.xlabel('Month')
plt.ylabel('Count')
plt.grid(True)
plt.xticks(rotation=45)
plt.legend(title='Legend', loc='upper left')
plt.show()


Подробнее здесь: https://stackoverflow.com/questions/790 ... dataframes
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Поиск оставшихся строк в кадрах данных pandas
    Anonymous » » в форуме Python
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Поиск оставшихся строк в кадрах данных pandas
    Anonymous » » в форуме Python
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Поиск оставшихся строк в кадрах данных pandas
    Anonymous » » в форуме Python
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Как запустить пользовательскую регрессию в кадрах данных/больших кадрах bigquery (с использованием удаленных функций)
    Anonymous » » в форуме Python
    0 Ответы
    29 Просмотры
    Последнее сообщение Anonymous
  • Эффективный частичный поиск строк в больших кадрах данных pyspark.
    Anonymous » » в форуме Python
    0 Ответы
    29 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Python»