0

In this program I'd like to randomly choose one word from a json file

[My code]

1

I succesfully opend the file but i don't know how to access only one record inside "randwords" Thanks!!!

eshirvana
  • 23,227
  • 3
  • 22
  • 38

2 Answers2

0

Try this:

randwords.sample(1)

See: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sample.html

s510
  • 2,271
  • 11
  • 18
-1

You can access a pandas dataframe (the pd) with an operation called indexing. For example pd['data'] will let you have access to the data column. Refer to here for more information.
One specific function that you can benefit here is iloc. For example pd.iloc[0] will let you have access to the first row. Then you can specify which column you are interested int by calling the appropriate column name.

pd.idloc[0].data

This will return the data column of the first row. Using a random number instead of 0 will result in a random row obioulsy.

ARK1375
  • 790
  • 3
  • 19