-2

Have a dataframe 10000 rows and 10 columns (string, int, float). Try to write a python function to query, filter and save the output csv in current path on local disk. The function looks like:

query_function(dataframe, column1=None, column2=None, column3=None...)

All columns in the function are optional

I google the topic but didn't find anything really help. Can anyone help?

rejiba
  • 3
  • 1
  • See [this post](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) for how to construct a better question. – Stephen Rauch Feb 12 '17 at 06:25

1 Answers1

0
def query_function(dataframe, **kwargs):
    for key, value in kwargs.items():
        dataframe = dataframe[(df[key] == value)]
    dataframe.to_csv('dataframe.csv')

You call it with: query_function(dataframe, columnx=value, columny=value), and it will create a file named dataframe.csv in the current path.

cyprieng
  • 706
  • 6
  • 16