我正试图预测新冠肺炎在哥伦比亚的行为,在County_Region列中,删除哥伦比亚以外国家的所有行



我一直在Python中使用Pandas的Crop命令来删除行和列。我正试图预测新冠肺炎在哥伦比亚的表现。现在,我需要在Country_Aregion列中删除除哥伦比亚以外的所有国家的行,你能帮我吗?

数据(.csv(:https://drive.google.com/file/d/1eEZfBmMQTlJjx1PSmC3bamukqhxR_oAy/view?usp=sharing

Python 1Python 2

此问题的目的是分离Country_ARegion==哥伦比亚的数据。这使您有机会继续进行进一步的评估。

  1. 步骤:读取csv数据
  2. 步骤:应用选择
  3. 步骤:只取结果
# Do the import
import pandas as pd
# Step 1: Row 0 is defined as the header of the object
df = pd.read_csv('10-01-2020.csv', header=0)
# Apply the selection
df2 = df[df['Country_Region'] == 'Colombia']
# Write the result into a new csv at the same place the script is existing
df2.to_csv('answer.csv')

结果answer.csv中只有哥伦比亚的一排排。

最新更新