- DataFrame.index
- DataFrame.columns
- DataFrame.at
- DataFrame.iat
- DataFrame.loc
- DataFrame.iloc
In this article, we will further look at the other methods of the DataFrame object, we will continue to explore the DataFrame object methods in a few more chapters before moving forward to the other Pandas objects.
If we want to know what is the label name for the index and the column of a DataFrame table, we can use the below DataFrame properties.
df.index df.columns

We can access any data in the DataFrame table with the following methods.
DataFrame.at # provide the [index name, column name] data location DataFrame.iat # provide the [row index, column index] of the data
import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(6, 4), index=[0, 1, 2, 3, 4, 5], columns=['A', 'B', 'C', 'D']) print(df) print(df.at[4, 'B']) print(df.iat[4, 3])

Besides that, we can also change the data within the table with below command.
df.at[4, 'B'] = 0.05 df.iat[4, 3] = 0.06
The next two methods are the same, we just need an index label to access the data value of the entire column.
import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(6, 4), index=[0, 1, 2, 3, 4, 5], columns=['A', 'B', 'C', 'D']) print(df) print(df.loc[2]) print(df.iloc[4])

We can even access a single data by providing a tuple of the index and the column name.
import pandas as pd import numpy as np df = pd.DataFrame(np.random.randn(6, 4), index=[0, 1, 2, 3, 4, 5], columns=['A', 'B', 'C', 'D']) print(df) print(df.loc[(2), 'C'])

There you have it, we will continue to explore the methods of the DataFrame object in the next chapter of this web analysis project series. If you like this post, don’t forget to subscribe to other rss feeds series as well!
from Planet Python
via read more
No comments:
Post a Comment