if HL[m].str.contains('Mole_fraction_of') : AttributeError: 'str' object has no attribute 'str'
时间: 2023-10-31 09:46:01 浏览: 90
It seems that you are trying to use the `.str` method on a string object `HL[m]`. The `.str` method is used on Pandas Series or DataFrame objects to operate on each element of the series or dataframe as a string.
To fix this error, you need to check if `HL[m]` is a Pandas Series or DataFrame object before using the `.str` method. If it is a string object, you can use string methods such as `.split()` or `.startswith()` to manipulate the string.
相关问题
if HL[m].str.contains('Mole_fraction_of') : AttributeError: 'str' object has no attribute 'str'
This error occurs because the variable HL[m] is a string and the .str attribute can only be used with pandas Series or DataFrames.
To fix this error, you can convert the string into a pandas Series or DataFrame using the pd.Series() or pd.DataFrame() function and then use the .str attribute.
For example:
```
HL_series = pd.Series(HL[m])
if HL_series.str.contains('Mole_fraction_of'):
# do something
```
Python+HL[m].str.contains('Mole_fraction')
This code snippet checks if the string 'Mole_fraction' is contained in the string HL[m]. If it is, the method will return True, otherwise it will return False.
阅读全文