OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Substring value not found in dataframe

  • Thread starter Thread starter Spyros Resvanis
  • Start date Start date
S

Spyros Resvanis

Guest
I've got the following bit of code where I have created the dataframe 'nvaluestrans'. I want to check the indexes of this dataframe for the text defined in the 'substring' variable. I have manually checked the nvaluetrans.index results and indeed the substring variable should be found. When I run the code, however, it always fails to find it. What am I doing wrong?

#Read data from csv file and create a dataframe called 'df'. 'df' transformed to 'nvalues' which contains #the useful data from the original file

Code:
df=pd.read_csv('C:\Python Coding Files\EXAMPLE PROJECT 1- REGIONAL PRODUCTIVITY METRICS\Regional productivity time series.csv')
nvalues=df.loc[7:31]

#'nvalues' is split into two dataframes called 'JF' (Gross Value Added_Per Job Filled) & 'HW' (Gross Value #Added_Per Hour Worked) nvaluestrans=nvalues.T substring="'GVA per hour worked: GOR North East (Index UK=100)'"

Code:
if any(substring in idx for idx in nvaluestrans.index) :
    print("Found")
else:
    print("not found")

I have checked the spelling of the 'substring' variable value and it is an exact match with the value in the nvaluetrans.index.
<p>I've got the following bit of code where I have created the dataframe 'nvaluestrans'. I want to check the indexes of this dataframe for the text defined in the 'substring' variable. I have manually checked the nvaluetrans.index results and indeed the substring variable should be found. When I run the code, however, it always fails to find it. What am I doing wrong?</p>
<p>#Read data from csv file and create a dataframe called 'df'. 'df' transformed to 'nvalues' which contains #the useful data from the original file</p>
<pre><code>df=pd.read_csv('C:\Python Coding Files\EXAMPLE PROJECT 1- REGIONAL PRODUCTIVITY METRICS\Regional productivity time series.csv')
nvalues=df.loc[7:31]
</code></pre>
<p>#'nvalues' is split into two dataframes called 'JF' (Gross Value Added_Per Job Filled) & 'HW' (Gross Value #Added_Per Hour Worked)
nvaluestrans=nvalues.T
substring="'GVA per hour worked: GOR North East (Index UK=100)'"</p>
<pre><code>if any(substring in idx for idx in nvaluestrans.index) :
print("Found")
else:
print("not found")
</code></pre>
<p>I have checked the spelling of the 'substring' variable value and it is an exact match with the value in the nvaluetrans.index.</p>
 
Top