Asking user to plot two columns in a csv file without him typing the entire column name?
<p>My current code:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code>import pandas as pd

df = pd.DataFrame.from_csv('data.csv',index_col=False)


while True:
     print (df)
     print ('Select X-Axis')
     xaxis = input()
     print ('Select Y-Axis')
     yaxis = input()
     break
 
df.plot(x= xaxis, y= yaxis)</code></pre>
</div>
</div>
</p>

<p>My current works only if user types out the entire column name. However, some of the columns are large. I want to make it easier for my user so that if he types out part of the column name it works. Or if somehow I can assign each column name with a number without manually going through each column and assigning a number. Then I can show a list to the user and he types out the number he would like to plot.</p>

<p>One way to do is to use filter in pandas for that purpose.</p>

<pre><code>df.filter(regex=(yaxis))
</code></pre>

<p>It will display all the columns matching that substring of yaxis</p>

<p>here is an example.</p>

<pre><code>A = { 'Name': [ 'John', 'Andrew', 'Smith'] , 'Age' : [20,23,42]}

A
Out[19]: {'Age': [20, 23, 42], 'Name': ['John', 'Andrew', 'Smith']}

df = pd.DataFrame(A)

df
Out[21]: 
   Age    Name
0   20    John
1   23  Andrew
2   42   Smith

df.filter(regex=('Na'))
Out[22]: 
     Name
0    John
1  Andrew
2   Smith

df.filter(regex=('e'))
Out[23]: 
   Age    Name
0   20    John
1   23  Andrew
2   42   Smith
</code></pre>

python pandas