如何收集同一日期的数据并创建新表

2024-04-29 12:48:50 发布

您现在位置:Python中文网/ 问答频道 /正文

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt  d

df = pd.read_csv("coronavirus2_dataset.csv",sep=",") df.head(20)
df.head(20)

enter image description here

在这里,我想收集同一日期的数据并创建一个新表。我怎样才能做到这一点


Tags: csvimportnumpypandasdfreadmatplotlibas
1条回答
网友
1楼 · 发布于 2024-04-29 12:48:50

您可以通过以下方式获取具有特定日期的数据:

df[df.Date == "01/22/2020 12:00:00"]

要将其作为行添加到新数据集中,请执行以下操作:

df_new = pd.DataFrame()  # Create a new, empty, dataframe
df_new.append(df[df.Date == "01/22/2020 12:00:00"])  # Append the data with the specific date

相关问题 更多 >