从合并的数据文件中删除数据?

时间:2018-03-05 18:02:37

标签: python pandas

我正处于学习如何使用Pandas的最初阶段,并且最近合并了两个文件:

#!/usr/bin/python3.5
import pandas as pd
fields = ['Title', 'Year', 'Length', 'Director']
X = pd.read_csv('Films.csv',skipinitialspace=True, usecols=fields, encoding = "ISO-8859-1")
fields2 = ['Title', 'Year', 'Length', 'budget', 'rating', 'Action', 'Animation', 'Comedy', 'Drama', 'Documentary', 'Romance', 'Short']
Y = pd.read_csv('Movies.csv',skipinitialspace=True, usecols=fields2, encoding = "ISO-8859-1")
FilmMovies = pd.merge(X, Y, on=['Title'])

我现在要做的是从此合并文件中删除所有重复标题的实例,以及预算为N / A的任何实例。我会用什么命令来做这件事?谢谢!

2 个答案:

答案 0 :(得分:1)

这应该做你想要的:

new_df = FilmMovies.drop_duplicates('Title').dropna(subset=['budget'])

答案 1 :(得分:0)

也许

df.drop_duplicates("Title")
df.drop_na(subset=["budget"])